2
用下面的代碼,我可以使用Python,NumPy的和FFmpeg的二進制文件FFMPEG視頻的管框架:管道與Python子進程FFmpeg的凍結
from __future__ import print_function
import subprocess
import numpy as np
import sys
npshape = [480, 480]
cmd_out = ['ffmpeg',
'-y', # (optional) overwrite output file if it exists
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-s', '%dx%d'%(npshape[1], npshape[0]), # size of one frame
'-pix_fmt', 'rgb24',
'-r', '24', # frames per second
'-i', '-', # The input comes from a pipe
'-an', # Tells FFMPEG not to expect any audio
'-vcodec', 'mpeg4',
'output.mp4']
fout = subprocess.Popen(cmd_out, stdin=subprocess.PIPE, stderr=subprocess.PIPE).stdin
for i in range(24*40):
if i%(24)==0:
print('%d'%(i/24), end=' ')
sys.stdout.flush()
fout.write((np.random.random(npshape[0]*npshape[1]*3)*128).astype('uint8').tostring())
fout.close()
,如果我寫的東西少也能正常工作價值超過37秒的框架,但如果我嘗試寫更多東西,代碼就會掛起。這種行爲的根本原因是什麼?我該如何解決它?
要告訴:'STDERR = subprocess.PIPE',則忽略它完全是一個災難。 –