如何从MPEG2 TS文件中提取原始YUV文件?

时间:2011-04-07 04:57:05

标签: ffmpeg

我有一个1920x1080 mpeg2 .ts文件。我需要获取每帧的原始YUV文件。 我试过ffmpeg但没有运气。我最终得到了许多小文件。我希望每帧都是1920x1080x1.5 = 3110400字节。

[root@dwarch frames]# ffmpeg -i video.ts -f image2 foo-%03d.yuv
FFmpeg version git-N-28713-g65daa94, Copyright (c) 2000-2011 the FFmpeg developers
  built on Mar 30 2011 09:20:16 with gcc 4.6.0
  configuration: --prefix=/usr --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-version3 --enable-nonfree --enable-runtime-cpudetect --disable-debug
  libavutil    50. 40. 0 / 50. 40. 0
  libavcodec   52.116. 0 / 52.116. 0
  libavformat  52.104. 0 / 52.104. 0
  libavdevice  52.  4. 0 / 52.  4. 0
  libavfilter   1. 76. 0 /  1. 76. 0
  libswscale    0. 13. 0 /  0. 13. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mpegts, from 'video.ts':
  Duration: 00:04:51.58, start: 0.333333, bitrate: 36041 kb/s
  Program 10 
    Stream #0.0[0x20]: Video: mpeg2video (Main), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 35000 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
    Stream #0.1[0x21]: Audio: ac3, 48000 Hz, 5.1, s16, 224 kb/s
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer @ 0x97148c0] w:1920 h:1080 pixfmt:yuv420p
[setdar @ 0x9714df0] a:16/9
[setdar @ 0x9714df0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'Parsed filter 0 setdar'
[scale @ 0x9711db0] w:1920 h:1080 fmt:yuv420p -> w:1920 h:1080 fmt:yuvj420p flags:0x4
[setdar @ 0x9714df0] w:1920 h:1080 -> dar:16/9 sar:1/1
Output #0, image2, to 'foo-%03d.yuv':
  Metadata:
    encoder         : Lavf52.104.0
    Stream #0.0: Video: mjpeg, yuvj420p, 1920x1080 [PAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
Stream mapping:
  Stream #0.0 -> #0.0

2 个答案:

答案 0 :(得分:6)

您也可以使用选项-vframes获取单个yuv帧,如下所示:

ffmpeg -i video.ts -pix_fmt yuv420p -vframes 1 foo-1.yuv

答案 1 :(得分:1)

当您使用图像作为格式(-f image2)时,它采用mjpeg格式,即图像压缩格式。所以,是的,你的解决方案是正确的,你需要删除-f image2。