Getting realtime output from ffmpeg to be used in progress bar (PyQt4, stdout)

后端 未结 7 1100
感情败类
感情败类 2020-12-02 10:08

I\'ve looked at a number of questions but still can\'t quite figure this out. I\'m using PyQt, and am hoping to run ffmpeg -i file.mp4 file.avi and get the out

相关标签:
7条回答
  • 2020-12-02 10:56

    In this specific case for capturing ffmpeg's status output (which goes to STDERR), this SO question solved it for me: FFMPEG and Pythons subprocess

    The trick is to add universal_newlines=True to the subprocess.Popen() call, because ffmpeg's output is in fact unbuffered but comes with newline-characters.

    cmd = "ffmpeg -i in.mp4 -y out.avi"
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)
    for line in process.stdout:
        print(line)
    

    Also note that in this code sample the STDERR status output is directly redirected to subprocess.STDOUT

    0 讨论(0)
提交回复
热议问题