<p>So I finally found an answer on stackoverflow.com. Check this answer for detailed parameters explanation:</p>
<p><a href="https://stackoverflow.com/questions/15778774/using-ffmpeg-to-losslessly-convert-yuv-to-another-format-for-editing-in-adobe-pr#15780960">https://stackoverflow.com/questions/15778774/using-ffmpeg-to-losslessly-convert-yuv-to-another-format-for-editing-in-adobe-pr#15780960</a></p>
<p>In short use this command to generate lossless x264</p>
<pre><code>ffmpeg -f rawvideo -vcodec rawvideo -s 1920x1080 -r 25 -pix_fmt yuv420p -i inputfile.yuv -c:v libx264 -preset ultrafast -qp 0 output.mp4
</code></pre>
<p>To check is it really losseless use this command:</p>
<pre><code>ffmpeg -i input.mp4 -f rawvideo -vcodec rawvideo -pix_fmt yuv420p -s 1920x1080 -r 25 rawvideo.yuv
</code></pre>
<p>And then I do:</p>
<pre><code>diff inputfile.yuv rawvideo.yuv
</code></pre>
<p>If there is no output, files are the same.</p>

CC BY-SA 4.0
2022-08-14T14:12:02.913Z
2022-08-14T14:13:28.433Z
2022-08-14T14:13:28.433Z
OuttaControl
<p>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.</p>
<p>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.</p>
<p>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:
<a href="https://www.raspberrypi.com/documentation/accessories/camera.html" rel="nofollow noreferrer">https://www.raspberrypi.com/documentation/accessories/camera.html</a>
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
<a href="https://ibb.co/mXKwqLL" rel="nofollow noreferrer">https://ibb.co/mXKwqLL</a>
<a href="https://ibb.co/mXKwqLL" rel="nofollow noreferrer"></a></p>
<p>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.</p>
<p>Command I Used to play video:</p>
<pre><code>ffplay test23.yuv -video_size 256x256 -f rawvideo -pixel_format yuv420p
</code></pre>
<p>Command I used to record the video</p>
<pre><code>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
</code></pre>
<p>Here is link to video:
<a href="https://drive.google.com/file/d/1guvv4x7MuJ15H_g6v9EXuImZ2Xy-lghF/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1guvv4x7MuJ15H_g6v9EXuImZ2Xy-lghF/view?usp=sharing</a></p>

CC BY-SA 4.0
2022-08-12T15:39:15.887Z
Welcome! Can you share a sample source file and the full ffmpeg command that you used?
Michael Liebman
CC BY-SA 4.0
2022-08-12T18:48:49.890Z
Thanks! I have updated question.
OuttaControl
CC BY-SA 4.0
2022-08-14T13:36:04.743Z
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
OuttaControl
<conversion><h.264><transcoding><huffyuv>
YUV420 to losseless
OuttaControl
# YUV420 to losseless

(Asked by: username_0 on 2022-08-12)

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

**Tags:** conversion, h.264, transcoding, huffyuv

> **Comments:**
> **username_1**: Welcome! Can you share a sample source file and the full ffmpeg command that you used?  
> **username_0**: Thanks! I have updated question.  
> **username_0**: 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  

---

## 1 answers

### Answer by username_0 on 2022-08-14. Score: 0 | Accepted answer

So I finally found an answer on stackoverflow.com. Check this answer for detailed parameters explanation:
https://stackoverflow.com/questions/15778774/using-ffmpeg-to-losslessly-convert-yuv-to-another-format-for-editing-in-adobe-pr#15780960
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.


---

