FFMPEG等待关闭管道以开始处理数据
我在这个问题上挣扎。 在这里,我试图使用来自图像和音频文件的FFMPEG流式传输视频,此代码在下面工作正常,但是在stdin关闭后它开始流式传输,我希望FFMPEG在接收到的管道输入时开始处理该管道输入,并立即输出结果。
p = subprocess.Popen(
[
'ffmpeg',
'-y',
'-re',
'-f', 'image2pipe',
'-vcodec', 'mjpeg',
'-framerate', '15',
'-analyzeduration', '2147483647',
'-probesize', '2147483647',
'-i', '-',
'-vn', '-i', audio_path,
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-c:a', 'aac',
'-f', 'flv',
rtmp_url
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
)
time.sleep(2)
i = 0
while True:
current_images = [name for name in os.listdir(img_dir) if os.path.isfile(os.path.join(img_dir, name))]
current_images = sorted(current_images)
if i > fnum-1:
print("frame read failed")
break
try:
img = cv2.imread(os.path.join(img_dir, current_images[i]))
success, buffer = cv2.imencode('.jpg', img)
frame = buffer.tobytes()
p.stdin.write(frame)
i += 1
except:
time.sleep(2)
pass
p.stdin.close()
p.wait()
为什么FFMPEG等待关闭管道开始处理?可以配置为启动接收流的实时转码吗?
您知道如何说服FFMPEG立即开始产生输出吗?
谢谢你!
I'm struggling with this issue.
Here I am trying to stream video using ffmpeg from images and audio file this code below works fine but it is start streaming after stdin closed, I would expect ffmpeg to start processing the pipe input as it is received, and immediately output the result.
p = subprocess.Popen(
[
'ffmpeg',
'-y',
'-re',
'-f', 'image2pipe',
'-vcodec', 'mjpeg',
'-framerate', '15',
'-analyzeduration', '2147483647',
'-probesize', '2147483647',
'-i', '-',
'-vn', '-i', audio_path,
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-c:a', 'aac',
'-f', 'flv',
rtmp_url
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
)
time.sleep(2)
i = 0
while True:
current_images = [name for name in os.listdir(img_dir) if os.path.isfile(os.path.join(img_dir, name))]
current_images = sorted(current_images)
if i > fnum-1:
print("frame read failed")
break
try:
img = cv2.imread(os.path.join(img_dir, current_images[i]))
success, buffer = cv2.imencode('.jpg', img)
frame = buffer.tobytes()
p.stdin.write(frame)
i += 1
except:
time.sleep(2)
pass
p.stdin.close()
p.wait()
Why is ffmpeg waiting to close the pipe to start processing? Can it be configured to start a live transcoding of the received stream?
Do you know how can I convince ffmpeg to start producing output immediately?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论