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

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

    If you have the duration (Which you can also get from the FFMPEG output) you can calculate the progress by reading the elapsed time (time) output when encoding.

    A simple example:

      pipe = subprocess.Popen(
            cmd,
            stderr=subprocess.PIPE,
            close_fds=True
      )
      fcntl.fcntl(
            pipe.stderr.fileno(),
            fcntl.F_SETFL,
            fcntl.fcntl(pipe.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK,
      )
       while True:
                readx = select.select([pipe.stderr.fileno()], [], [])[0]
    
                if readx: 
                    chunk = pipe.stderr.read()
    
                    if not chunk:
                        break
    
                    result = re.search(r'\stime=(?P

提交回复
热议问题