lbryio / lbry-sdk

The LBRY SDK for building decentralized, censorship resistant, monetized, digital content apps.
https://lbry.com
MIT License
7.19k stars 483 forks source link

transcoding next steps - parameters, delete file, progress, error codes #2867

Open tzarebczan opened 4 years ago

tzarebczan commented 4 years ago
BrannonKing commented 4 years ago

Max bitrate, target bitrate, and max resolution can already be set in the conf file. I suppose that does not allow for on-the-fly or per-request adjustment, though.

    video_bitrate_maximum = Integer('Maximum bits per second allowed for video streams (0 to disable).', 8400000)
    video_scaler = String('FFmpeg scaling parameters for reducing bitrate. '
                          'Example: -vf "scale=-2:720,fps=24" -maxrate 5M -bufsize 3M',
                          r'-vf "scale=if(gte(iw\,ih)\,min(2560\,iw)\,-2):if(lt(iw\,ih)\,min(2560\,ih)\,-2)" '
                          r'-maxrate 8400K -bufsize 5000K')
kamotswind commented 4 years ago

This example, while using PHP instead of Python, should help with the progress indication task: https://stackoverflow.com/a/11455839

I'd suggest not outputting to a text file and just capture the output right in to Python. Maybe something like this:

import pexpect

cmd = 'ffmpeg -i file.MTS file.avi'
thread = pexpect.spawn(cmd)
print "started %s" % cmd
cpl = thread.compile_pattern_list([
    pexpect.EOF,
    "frame= *\d+",
    '(.+)'
])
while True:
    i = thread.expect_list(cpl, timeout=None)
    if i == 0: # EOF
        print "the sub process exited"
        break
    elif i == 1:
        frame_number = thread.match.group(0)
        print frame_number
        thread.close
    elif i == 2:
        #unknown_line = thread.match.group(0)
        #print unknown_line
        pass

Taken from: https://stackoverflow.com/questions/7632589/getting-realtime-output-from-ffmpeg-to-be-used-in-progress-bar-pyqt4-stdout