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

后端 未结 7 1135
感情败类
感情败类 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:47

    1. Calling from the shell is generally not required.
    2. I know from experince that part of the ffmpeg output comes on stderr, not stdout.

    If all you want to do is print the output line, like in your example above, then simply this will do:

    import subprocess
    
    cmd = 'ffmpeg -i file.mp4 file.avi'
    args = cmd.split()
    
    p = subprocess.Popen(args)
    

    Note that the line of ffmpeg chat is terminated with \r, so it will overwrite in the same line! I think this means you can't iterate over the lines in p.stderr, as you do with your rsync example. To build your own progress bar, then, you may need to handle the reading yourself, this should get you started:

    p = subprocess.Popen(args, stderr=subprocess.PIPE)
    
    while True:
      chatter = p.stderr.read(1024)
      print("OUTPUT>>> " + chatter.rstrip())
    

提交回复
热议问题