Question

How to convert set of YUV frames to a Video and later convert the video to YUV frames without any loss using C ?(I dont want to convert it to RGB in between)

Was it helpful?

Solution

if you have a raw YUV file, you need to tell ffmpeg which pixel format/subsampling that is used. YUV have no header, so you also need to specify the width and height of the data.

The following ffmpeg commands encodes a 1080p YUV 4:2:0 to H.264 using the x264 encoder and place the result in a mp4-container. This operation is however not losless.

ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 25 -i input.yuv \
-c:v libx264 output.mp4

To get the YUV-frames back again, do

ffmpeg -i output.mp4 frames.yuv

If you are looking for a lossless encoder, try HuffYUV or FFV1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top