31

Is it possible to create a raw YUV video from H264 encoded video using ffmpeg? I want to open the video with matlab and access Luma, Cb and Cr components frame by frame.

Necip Onur Uzun
  • 1,115
  • 3
  • 13
  • 16

1 Answers1

55

Yes you can, you just have to specific the pixel format. To get the whole list of the format:

ffmpeg -pix_fmts | grep -i pixel_format_name

For example if you want to save the 1st video track of an mp4 file as a yuv420p (p means planar) file:

ffmpeg -i video.mp4 -c:v rawvideo -pix_fmt yuv420p out.yuv
maartenba
  • 3,344
  • 18
  • 31
alexbuisson
  • 7,699
  • 3
  • 31
  • 44
  • 2
    First I got this error: Unrecognized option 'c:v' Then, I used "-vcodec rawvideo" instead of "-c:v rawvideo" and it's worked. Thanks! – Necip Onur Uzun Dec 16 '13 at 13:27
  • 3
    -c:v and -c:a should be ok with recent version of ffmpeg, you may run an old one, consider to update your version if you can :) – alexbuisson Dec 16 '13 at 13:37
  • Anyone else get a bunch of multi-colored lines? Also the conversion happens instantly which doesn't seem right to me...? – Joshua F. Rountree May 28 '15 at 14:50
  • @JoshuaF.Rountree You need to specify the dimensions in order to be able to view it (e.g., in VLC): https://stackoverflow.com/a/22313305/2442139 – tomtheengineer Oct 16 '17 at 22:23
  • working command : ffmpeg -i input.264 -vcodec rawvideo -pix_fmt yuv420p output.yuv – Abdullah Farweez Jul 13 '18 at 11:38
  • is there a way to store timestamps? – thang Jul 23 '18 at 20:55
  • 1
    @thang if you have keep timestamp + raw video frame, you can follow 2 different way. 1st, combine ffmpeg to decode the raw frame and ffprobe --show_frame (or something like that..) to dump frames information and grep their pts. After that interleave those 2 information source (I think I used a simple python script to read 2 procress stdout and mux them on the output) not that I also often parse an ffmpeg -i filename output to get resolution and frame-rate to build a fully independant and compact format for raw video data like that: W,H,FPS, PTS, FRAME, .... PTS, FRAME ... – alexbuisson Aug 17 '18 at 09:56