【发布时间】:2016-07-16 01:44:47
【问题描述】:
我不知道为什么,但avconv 似乎并没有像我预期的那样播放原始视频。
我正在尝试将视频从ffmpeg 传输到python(最终我想从x11grab 读取,而不是视频文件)。它在我的 Macbook 上使用 ffmpeg 运行良好,但是当我在 Debian Jessie 上使用 avconv 时,流提前中断了!
这是我的基本 python,它在 this guide 之后:
input_resolution_shape = (1280,800,3)
input_bytes = reduce(mul, input_resolution_shape, 1)
print input_bytes
# Prints 3072000
import subprocess as sp
command = [ FFMPEG_BIN, # This is either "avconv" or "ffmpeg".
'-i', 'test_video.mp4',
'-f', 'image2pipe',
'-pix_fmt', 'rgb24',
'-vcodec', 'rawvideo', '-']
pipe = sp.Popen(command, stdout = sp.PIPE, bufsize=10**8)
import numpy
for _ in range(100): # read 100 frames
# read 1280*800*3 bytes (= 1 frame)
raw_image = pipe.stdout.read(input_bytes)
# transform the byte read into a numpy array
image = numpy.fromstring(raw_image, dtype='uint8')
if image.size != 0:
print image.size
# Prints 1015808
在 mac 上,打印的 image.size 与 input_bytes 相同,3072000。但在 debian 上,它是 1015808。任何想法为什么会发生这种情况?
有趣的是,3072000/1015808 大约是 3:
In [1]: 3072000./1015808.
Out[1]: 3.024193548387097
【问题讨论】:
-
acvonv不等同于ffmpeg。你为什么不直接使用ffmpeg?您可以简单地download a staticffmpegbinary 并将您的脚本指向它。 -
因为我在 Debian 上,我不知道如何正确安装 ffmpeg。 :(
标签: python video ffmpeg avconv