I am using Raspberrypi HiQ camera to capture High Speed(120fps) videos of planets for astronomy purposes. Using libcamera-vid I can record h264 upto 4.2 but I saw h264 has limitation of 60fps. I wouldn't mind that if I do not loose any frames(video slowed down), but on the other hand I believe that recording in h264 would result in losses? And it is necessary for my purposes that I do not loose any bit of real data. So compression is fine, but lossy is not.

Libcamera-vid can also record in mjpeg, and uncompressed and unformatted YUV420. The latter is interesting to me, but unfortunately I am having trouble decoding it... I learned that ffmpeg can convert it to other formats. As far as I care it even doesn't even have to be a video, series of TIFFs, FITS, SEQ are fine for me. The software I am using is accepts a long list of video and image files, but not yuv.

I tried converting and playing it but I got passing green lines of different saturation on black background... Not planet Saturn :) I saw there are different types of yuv420, but raspi documentation does not give whole lot information on it: https://www.raspberrypi.com/documentation/accessories/camera.html So in short what tool, or command, on linux or windows, can I use to convert this yuv420 to any losseless format from list bellow https://ibb.co/mXKwqLL

or I can even use h264 without fear of losing data? Any alternative is acceptable from my side I am just interested in having video/images that I can work with.

Command I Used to play video:

ffplay test23.yuv -video_size 256x256 -f rawvideo -pixel_format yuv420p

Command I used to record the video

libcamera-vid --codec yuv420 --qt-preview  --analoggain 24 --shutter 8000 --framerate 120 --frames 2500 --mode 1332:990:10:P --roi 0.1,0.1,0.5,0.5 -o /mnt/ramdisk/test23.yuv --width 256 --height 256

Here is link to video: https://drive.google.com/file/d/1guvv4x7MuJ15H_g6v9EXuImZ2Xy-lghF/view?usp=sharing

  • Welcome! Can you share a sample source file and the full ffmpeg command that you used? Aug 12, 2022 at 15:39
  • Thanks! I have updated question. Aug 12, 2022 at 18:48
  • I have managed to generate something I can use, now I need to make sure it is losseless this js the command ffmpeg -y -s 256x256 -pix_fmt yuv420p -i ~/Public/raw/test23.yuv -c:v libx264 -pix_fmt yuv420p -profile:v high444 -crf 0 -preset:v slow tedt23_lossless.avi Aug 14, 2022 at 13:36

1 Answer 1


So I finally found an answer on stackoverflow.com. Check this answer for detailed parameters explanation:


In short use this command to generate lossless x264

ffmpeg -f rawvideo -vcodec rawvideo -s 1920x1080 -r 25 -pix_fmt yuv420p -i inputfile.yuv -c:v libx264 -preset ultrafast -qp 0 output.mp4

To check is it really losseless use this command:

ffmpeg -i input.mp4 -f rawvideo -vcodec rawvideo -pix_fmt yuv420p -s 1920x1080 -r 25 rawvideo.yuv

And then I do:

diff inputfile.yuv rawvideo.yuv

If there is no output, files are the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.