Encode video losslessly with NVidia Video Encoder

I try to encode a raw video with gray format losslessly using ffmpeg compiled with cuda as in [url]https://developer.nvidia.com/ffmpeg[\url]

The command that I used is:

ffmpeg -y -f rawvideo -s:v 640x480 -r 60 -pix_fmt gray -i input -c:v h264_nvenc -preset lossless -qp 0 -pix_fmt yuv420p output.mp4

And decoded it with:

ffmpeg -y -vsync 0 -c:v h264_cuvid -i output.mp4 -f rawvideo -pix_fmt gray output.yuv

And then I compare the input with the output.yuv file with:

diff input output.yuv

And the two files are not identical.

I don’t find any document on the quality of video with -preset set to lossless.

Is the compressed video really lossless ?

Thanks

Found that h264_nvenc converts frames in gray format to yuv420p format and that makes changes in pixel when reconvert back to gray.

If you input a yuv420p raw file into h264_nvenv with -preset lossless -rc constqp -qp 0. The output mp4 will be losslessly compressed.

Hope this helps

I also Found that h264_nvenc converts frames in gray format to yuv420p format.