How to extract YUV source files from MPEG2 TS file?

I have a 1920x1080 mpeg2.ts file. I need to get raw YUV files for each frame. I tried ffmpeg but no luck. As a result, I have many small files. I expect each frame to be 1920x1080x1.5 = 3110400 bytes.

[ 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 
+4
source share
2 answers

You can also use the -vframes option to get one yuv frame, as shown below:

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

When using an image as the format (-f image2), it assumes the mjpeg format, which is an image compression format. So yes, your solution is correct, you need to remove -f image2.

+1
source

Source: https://habr.com/ru/post/1347035/


All Articles