convert H264 video to raw YUV format

74,527

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
Share:
74,527
Necip Onur Uzun
Author by

Necip Onur Uzun

Updated on January 16, 2020

Comments

  • Necip Onur Uzun
    Necip Onur Uzun over 4 years

    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
    Necip Onur Uzun over 10 years
    First I got this error: Unrecognized option 'c:v' Then, I used "-vcodec rawvideo" instead of "-c:v rawvideo" and it's worked. Thanks!
  • alexbuisson
    alexbuisson over 10 years
    -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 :)
  • Joshua F. Rountree
    Joshua F. Rountree almost 9 years
    Anyone else get a bunch of multi-colored lines? Also the conversion happens instantly which doesn't seem right to me...?
  • tomtheengineer
    tomtheengineer over 6 years
    @JoshuaF.Rountree You need to specify the dimensions in order to be able to view it (e.g., in VLC): stackoverflow.com/a/22313305/2442139
  • Abdullah Farweez
    Abdullah Farweez almost 6 years
    working command : ffmpeg -i input.264 -vcodec rawvideo -pix_fmt yuv420p output.yuv
  • thang
    thang almost 6 years
    is there a way to store timestamps?
  • alexbuisson
    alexbuisson almost 6 years
    @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 ...