使用 ffmpeg 将 yuv 视频转换为 png 帧
Convert yuv video to png frames using ffmpeg
我想使用 ffmpeg
.
将 yuv 视频转换为 png 帧
我使用的命令是
/root/bin/ffmpeg -i pirkagia_max_vid_qual_one.yuv -s 720x576 -r 25 -pix_fmt yuv420p -f image2 one/image-%3d.png
我收到以下回复:
ffmpeg version git-2015-08-07-8015150 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
libavutil 54. 30.100 / 54. 30.100
libavcodec 56. 57.100 / 56. 57.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 32.100 / 5. 32.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[IMGUTILS @ 0x7fffe8e84760] Picture size 0x0 is invalid
[IMGUTILS @ 0x7fffe8e84310] Picture size 0x0 is invalid
[rawvideo @ 0x3aaf160] Could not find codec parameters for stream 0 (Video: rawvideo (I420 / 0x30323449), yuv420p, -4 kb/s): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
pirkagia_max_vid_qual_one.yuv: could not find codec parameters
Input #0, rawvideo, from 'pirkagia_max_vid_qual_one.yuv':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, -4 kb/s, 25 tbr, 25 tbn, 25 tbc
Output #0, image2, to 'one/image-%3d.png':
Output file #0 does not contain any stream
有什么想法吗?
在您的情况下,rawvideo demuxer 需要更多信息。由于您的输入中似乎没有 header 指定视频参数,您必须指定它们才能正确解码数据。示例:
ffmpeg -pixel_format yuv420p -video_size 720x576 -framerate 25 -i …
此外,yuv420p
与 PNG 编码器不兼容,因此您可以将其作为输出选项删除,合适的像素格式为 auto-selected。
import os
num = 1
video_name = ['out.yuv']
short = ['yuv']
for i in range(num):
saveroot = 'images/' + short[i]
savepath = 'images/' + short[i] + '/im%03d.yuv'
if not os.path.exists(saveroot):
os.makedirs(saveroot)
print('ffmpeg -y -pix_fmt yuv420p -s 1920x1024 -i ' + 'videos_crop/' + video_name[i] + ' ' + savepath)
os.system('ffmpeg -y -pix_fmt yuv420p -s 1920x1024 -i ' + 'videos_crop/' + video_name[i] + ' ' + savepath)
我想使用 ffmpeg
.
我使用的命令是
/root/bin/ffmpeg -i pirkagia_max_vid_qual_one.yuv -s 720x576 -r 25 -pix_fmt yuv420p -f image2 one/image-%3d.png
我收到以下回复:
ffmpeg version git-2015-08-07-8015150 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
libavutil 54. 30.100 / 54. 30.100
libavcodec 56. 57.100 / 56. 57.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 32.100 / 5. 32.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[IMGUTILS @ 0x7fffe8e84760] Picture size 0x0 is invalid
[IMGUTILS @ 0x7fffe8e84310] Picture size 0x0 is invalid
[rawvideo @ 0x3aaf160] Could not find codec parameters for stream 0 (Video: rawvideo (I420 / 0x30323449), yuv420p, -4 kb/s): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
pirkagia_max_vid_qual_one.yuv: could not find codec parameters
Input #0, rawvideo, from 'pirkagia_max_vid_qual_one.yuv':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, -4 kb/s, 25 tbr, 25 tbn, 25 tbc
Output #0, image2, to 'one/image-%3d.png':
Output file #0 does not contain any stream
有什么想法吗?
在您的情况下,rawvideo demuxer 需要更多信息。由于您的输入中似乎没有 header 指定视频参数,您必须指定它们才能正确解码数据。示例:
ffmpeg -pixel_format yuv420p -video_size 720x576 -framerate 25 -i …
此外,yuv420p
与 PNG 编码器不兼容,因此您可以将其作为输出选项删除,合适的像素格式为 auto-selected。
import os
num = 1
video_name = ['out.yuv']
short = ['yuv']
for i in range(num):
saveroot = 'images/' + short[i]
savepath = 'images/' + short[i] + '/im%03d.yuv'
if not os.path.exists(saveroot):
os.makedirs(saveroot)
print('ffmpeg -y -pix_fmt yuv420p -s 1920x1024 -i ' + 'videos_crop/' + video_name[i] + ' ' + savepath)
os.system('ffmpeg -y -pix_fmt yuv420p -s 1920x1024 -i ' + 'videos_crop/' + video_name[i] + ' ' + savepath)