Piping to FFMPEG with Python subprocess freezes

后端 未结 1 1470
清酒与你
清酒与你 2021-01-19 07:05

With the following code, I am able to pipe frames of a video to FFMPEG using Python, Numpy and the FFMPEG binaries:

from __future__ import print_function
imp         


        
相关标签:
1条回答
  • 2021-01-19 07:35

    A highly probable culprit is the disgustingly stinky subprocess.Popen line. Not only you ignore its return value - which you must never do, in order to ensure the subprocess' completion by certain point and/or check its exit code - you also make stderr a pipe but never read it - so the process must be hanging when its buffer fills.

    This should fix it:

    p = subprocess.Popen(cmd_out, stdin=subprocess.PIPE)
    fout = p.stdin
    
    <...>
    
    fout.close()
    p.wait()
    if p.returncode !=0: raise subprocess.CalledProcessError(p.returncode,cmd_out)
    
    0 讨论(0)
提交回复
热议问题