Coder Social home page Coder Social logo

fbed's Introduction

FBED - FFmpeg Batch Encoding Dashboard

A commandline python application for monitoring the progress of video encoding with FFmpeg. FBED makes use of ffmpeg-python and urwid.

Usage

fbed.py takes the number of parallel ffmpeg tasks to run followed by the list of files or directories to encode. If passed a directory, the script will find all videos within the directory and its subdirectories. The encoded videos are output to encode_output in the working directory.

Usage:
    ./fbed.py <parallel_encodes> <items>...

Guide:
    <items> can be a single files or a directories. If a directory is passed all
    files in the directory and it subdirectories besides those in one named
    'encode_output' will be re-encoded

By default FBED will use the h264_v4l2m2m encoder for hardware accelerated encoding on the Raspberry Pi 4. You may need to build FFmpeg from source to get a recent version with some bugs in this encoder fixed (version 4.3 or higher is required). If you're using hardware accelerated encoding on the Raspberry Pi keep in mind the limitations of the hardware: It can only run a single 1080p encode at a time. If your videos are lower resultion it may be able to run 2 or 3 in parallel, but if the encoding appears to freeze check the log files written out in encode_output for errors.

Example image of the dashboard

Configuring FBED

FBED has a few settings hard-coded in it that I found to work well for my use case. The script will pick the output target bitrate based on the video resolution, which you can increase or decrease as desired by editing the script:

# Pick bitrate based on resolution, 1080p (8Mbps), 720p (5Mbps), smaller (3Mbps)
bitrate = "3M"
if info["height"] > 720:
    bitrate = "8M"
elif info["height"] > 480:
    bitrate = "5M"

You can also change the encoder used to select a different hardware encoder (e.g., h264_nvenc on Nvidia GPUs, h264_qsv on Intel CPUs, etc.) by changing the value of c:v in the encoding_args to your desired encoder. You can also pass additional arguments to the encoder by adding them here. If you're on the RPi4 using h264_v4l2m2m I recommend leaving the num_output_buffers and num_capture_buffers as I've set them, which raises their values above the defaults of 16 and 4 respectively. When running parallel encodes of 720p and smaller videos I would get warnings from ffmpeg that the capture buffers where flushed out to user space, and to consider increasing them. These are set high enough that I don't seem to get these warnings, though exceed the memory capacity of the encoder if trying to do two 1080p streams in parallel. In that case you'd want to set them to half their current value (i.e., to 16 and 8 respectively). Do not modify or remove progress parameter, as this is required by the dashboard.

encoding_args = {
    # HWAccel for RPi4, may need to pick a different encoder
    # for HW accel on other systems
    "c:v": "h264_v4l2m2m",
    "num_output_buffers": 32,
    "num_capture_buffers": 16,
    "b:v": bitrate,
    "c:a": "copy",
    "progress": f"pipe:{self.pipe_write}"
}

fbed's People

Contributors

sitdownrightnow avatar twinklebear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fbed's Issues

Bitrate errore with tvheadend recordings

This is what command tells me:

[matt@rpi3bp MattHDD]$ ./fbed.py 1 TV/A-Team-Iris.mkv
Collecting input video list...
Traceback (most recent call last):
  File "./fbed.py", line 284, in <module>
    manager = EncodingManager(all_files, parallel_encodes, frame, todo_list, active_list, completed_list)
  File "./fbed.py", line 158, in __init__
    bitrate = float(video_stream["bitrate"]) / 1000
KeyError: 'bitrate'

Here's media information:

[matt@rpi3bp MattHDD]$ mediainfo TV/A-Team-Iris.mkv
General
Unique ID                                : 261086048781300974404954431405333131508 (0xC46B580C83DE3464D19C09880FEBB0F4)
Complete name                            : TV/A-Team-Iris.mkv
Format                                   : Matroska
Format version                           : Version 2
File size                                : 918 MiB
Duration                                 : 46 min 0 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 2 791 kb/s
Movie name                               : A-Team
Writing application                      : Tvheadend 4.3-1916~g1884300f0-dirty
Writing library                          : Tvheadend Matroska muxer
Original source form                     : TV
DATE_BROADCASTED                         : 2020-12-07 06:20:00
SUMMARY                                  : Il nipote di un boss della malavita e' un appassionato di corse d'auto, che vuole vincere con ogni mezzo. Alla prossima corsa partecipa il nipote di Hannibal. /  / VISIONE ADATTA A TUTTI.
TVCHANNEL                                : Iris

Video
ID                                       : 1
Format                                   : MPEG Video
Format version                           : Version 2
Format profile                           : Main@Main
Format settings                          : CustomMatrix / BVOP
Format settings, BVOP                    : Yes
Format settings, Matrix                  : Custom
Format settings, GOP                     : Variable
Format settings, picture structure       : Frame
Codec ID                                 : V_MPEG2
Codec ID/Info                            : MPEG 1 or 2 Video
Duration                                 : 46 min 0 s
Bit rate mode                            : Variable
Bit rate                                 : 2 479 kb/s
Maximum bit rate                         : 15.0 Mb/s
Width                                    : 720 pixels
Height                                   : 576 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Standard                                 : PAL
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.239
Stream size                              : 816 MiB (89%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

Audio #1
ID                                       : 2
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : A_MPEG/L2
Codec ID/Hint                            : MP2
Duration                                 : 46 min 0 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -515 ms
Stream size                              : 42.1 MiB (5%)
Language                                 : Italian
Default                                  : Yes
Forced                                   : No

Audio #2
ID                                       : 3
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : A_MPEG/L2
Codec ID/Hint                            : MP2
Duration                                 : 46 min 0 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -414 ms
Stream size                              : 42.1 MiB (5%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

Text
ID                                       : 4
Format                                   : UTF-8
Codec ID                                 : S_TEXT/UTF8
Codec ID/Info                            : UTF-8 Plain Text
Language                                 : Italian
Default                                  : Yes
Forced                                   : No

decouple from urwid?

This is a great script and it's very useful. However, I would like to accomplish the same thing but without a terminal display. I've tried to decouple it from urwid but I cant seem to get it to work. Do you have this script uncoupled from urwid? I was hoping to decoupe it and add argparse

Advice on how/where to add extra ffmpeg filters

script works great! just looking to add a frame rate filter.
could you offer any pointers?
I found the following example in the ffmpeg-python documentation but i am unsure how to apply it to your code
(
ffmpeg
.input('dummy.mp4')
.filter('fps', fps=25, round='up')
.output('dummy2.mp4')
.run()
)
Any help would be appreciated
Regards
Anthony

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.