我使用ffmpeg-python模块将视频转换为图像。具体地说,我使用了ffmpeg-python的官方git代码库提供的代码,如下所示
out, _ = (
ffmpeg
.input(in_filename)
.filter('select', 'gte(n,{})'.format(frame_num))
.output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
.run(capture_stdout=True)
)
im = np.frombuffer(out, 'uint8')
print(im.shape[0]/3/1080)
# 924.907098765432原始视频的大小为( 1920,1080),pix_fmt为'yuv420p',但上述代码的输出不是1920。
我自己已经知道,ffmpeg.run()的输出不是一个解码的图像数组,而是一个以JPEG格式编码的字节串。要将映像恢复到numpy数组中,只需使用cv2.imdecode()函数。例如,
im = cv2.imdecode(im, cv2.IMREAD_COLOR)但是,我不能在我的嵌入式Linux系统上使用opencv。所以我现在的问题是,我可以直接从ffmpeg-python获得numpy输出,而不需要通过opencv转换它吗?
发布于 2019-11-09 20:50:44
要让ffmpeg-python直接输出原始图像数组,可以使用以下命令:
out, _ = (
ffmpeg
.input(in_filename)
.filter('select', 'gte(n,{})'.format(frame_num))
.output('pipe:', vframes=1, format='rawvideo', pix_fmt='rgb24')
.run(capture_stdout=True)
)
im = np.frombuffer(out, 'uint8')https://stackoverflow.com/questions/58778321
复制相似问题