therobin
20th November 2021, 03:36
I was experimenting with some lossless archiving and I think I found a bug in utvideo which I cannot get it to losslessly reproduce some optimized 8-bit color PNG files on input. I was using Elephants Dream 1080p PNGs as the input source.
What I found is that UTVideo will not preserve 8-bit color input images losslessly, but will for 1-bit and 24-bit color images.* I verified by outputting results back to 24-bit BMP and checking the MD5. The UTVideo gives verified lossless output for frames sourced from 1-bit colorspace optimized PNGs and the 24-bit colorspace optimized PNGs. But the frames from PNGs that were 8-bit colorspace when optimized are giving invalid checksums when exported to 24-bit BMP.
I also tested FFV1 encoding to use a control to ensure the issue was not with the way ffmpeg was processing the input images.* All FFV1 frames can be verified lossless whether it was encoded from the original Xiph PNGs or the optimized PNGs. I also tested the latest release build and master branch build from gyan.
I am looking to see if anyone can replicate my findings. You can download the complete 21G source here: https://media.xiph.org/ED/ED-1080-png.tar
But since the problem occurs in the first 1 second, I have packaged the first 30 frames here (both original Xiph source along with Xiph's original MD5 file and my optimized versions): https://www.mediafire.com/file/knisxsozg41001l/Elephants_Dream_First_30_Frames.7z/file
If you want to test optimizing it yourself, I used oxipng with -D command:https://github.com/shssoichiro/oxipng/releases
I also used RapidCRC Unicode to check MD5s on windows: https://www.ov2.eu/programs/rapidcrc-unicode
To replicate my result:
1. Encode the 30 frames to FFV1 and UTVideo:
ffmpeg -i ED-30-xiph-source\%05d.png -c:v ffv1 ED-xiph_ffv1.mkv
ffmpeg -i ED-30-xiph-source\%05d.png -c:v utvideo ED-xiph_utvideo.mkv
ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr0 -c:v ffv1 ED-opt_ffv1.mkv
ffmpeg -i ED-30-opt\%05d.png -c:v utvideo ED-opt_utvideo.mkv
NOTE: The pix_fmt bgr0 command is necessary when encoding from the optimized files to prevent ffmpeg from encoding to greyscale since the first optimized PNG is 1-bit color. It is actually not necessary for UTvideo since it does support a grey or mono colorspace so will default to the appropriate pixel format.
2. Export all videos and PNGs to BMPs:
ffmpeg -i ED-30-xiph-source\%05d.png BMP\ED-xiph-%02d.bmp
ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr24 BMP\ED-opt-%02d.bmp
ffmpeg -i ED-xiph_ffv1.mkv BMP\ED-xiph_ffv1-%02d.bmp
ffmpeg -i ED-xiph_utvideo.mkv BMP\ED-xiph_utvideo-%02d.bmp
ffmpeg -i ED-opt_ffv1.mkv BMP\ED-opt_ffv1-%02d.bmp
ffmpeg -i ED-opt_utvideo.mkv BMP\ED_opt_utvideo-%02d.bmp
3. Perform checksum on all results.
I find all BMPs have the same MD5 checksum except:
ED_opt_utvideo-12.bmp 02a34fc1e347889d5546b547fa63e6af
ED_opt_utvideo-13.bmp ca40ed9fc4acc827a4a77051433f0102
ED_opt_utvideo-14.bmp e3666199f35234756dddac97b8e18488
The above are sourced from the 8-bit optimized PNGs.
The correct MD5 is as following:
ED-xiph_utvideo-12.bmp ba5d92ca99726d837859b4b05795d317
ED-xiph_utvideo-13.bmp 735ee7c8b493855480fd0f5847a66132
ED-xiph_utvideo-14.bmp b509c3ac24e3543e1f59a7f1456e924d
Which are sourced from the original Xiph PNGs that are all 24-bit.
*EDIT: I change the topic title to reflect the real error being pal8 in ffmpeg as to prevent spreading misinformation about UTVideo. See discussion.
What I found is that UTVideo will not preserve 8-bit color input images losslessly, but will for 1-bit and 24-bit color images.* I verified by outputting results back to 24-bit BMP and checking the MD5. The UTVideo gives verified lossless output for frames sourced from 1-bit colorspace optimized PNGs and the 24-bit colorspace optimized PNGs. But the frames from PNGs that were 8-bit colorspace when optimized are giving invalid checksums when exported to 24-bit BMP.
I also tested FFV1 encoding to use a control to ensure the issue was not with the way ffmpeg was processing the input images.* All FFV1 frames can be verified lossless whether it was encoded from the original Xiph PNGs or the optimized PNGs. I also tested the latest release build and master branch build from gyan.
I am looking to see if anyone can replicate my findings. You can download the complete 21G source here: https://media.xiph.org/ED/ED-1080-png.tar
But since the problem occurs in the first 1 second, I have packaged the first 30 frames here (both original Xiph source along with Xiph's original MD5 file and my optimized versions): https://www.mediafire.com/file/knisxsozg41001l/Elephants_Dream_First_30_Frames.7z/file
If you want to test optimizing it yourself, I used oxipng with -D command:https://github.com/shssoichiro/oxipng/releases
I also used RapidCRC Unicode to check MD5s on windows: https://www.ov2.eu/programs/rapidcrc-unicode
To replicate my result:
1. Encode the 30 frames to FFV1 and UTVideo:
ffmpeg -i ED-30-xiph-source\%05d.png -c:v ffv1 ED-xiph_ffv1.mkv
ffmpeg -i ED-30-xiph-source\%05d.png -c:v utvideo ED-xiph_utvideo.mkv
ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr0 -c:v ffv1 ED-opt_ffv1.mkv
ffmpeg -i ED-30-opt\%05d.png -c:v utvideo ED-opt_utvideo.mkv
NOTE: The pix_fmt bgr0 command is necessary when encoding from the optimized files to prevent ffmpeg from encoding to greyscale since the first optimized PNG is 1-bit color. It is actually not necessary for UTvideo since it does support a grey or mono colorspace so will default to the appropriate pixel format.
2. Export all videos and PNGs to BMPs:
ffmpeg -i ED-30-xiph-source\%05d.png BMP\ED-xiph-%02d.bmp
ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr24 BMP\ED-opt-%02d.bmp
ffmpeg -i ED-xiph_ffv1.mkv BMP\ED-xiph_ffv1-%02d.bmp
ffmpeg -i ED-xiph_utvideo.mkv BMP\ED-xiph_utvideo-%02d.bmp
ffmpeg -i ED-opt_ffv1.mkv BMP\ED-opt_ffv1-%02d.bmp
ffmpeg -i ED-opt_utvideo.mkv BMP\ED_opt_utvideo-%02d.bmp
3. Perform checksum on all results.
I find all BMPs have the same MD5 checksum except:
ED_opt_utvideo-12.bmp 02a34fc1e347889d5546b547fa63e6af
ED_opt_utvideo-13.bmp ca40ed9fc4acc827a4a77051433f0102
ED_opt_utvideo-14.bmp e3666199f35234756dddac97b8e18488
The above are sourced from the 8-bit optimized PNGs.
The correct MD5 is as following:
ED-xiph_utvideo-12.bmp ba5d92ca99726d837859b4b05795d317
ED-xiph_utvideo-13.bmp 735ee7c8b493855480fd0f5847a66132
ED-xiph_utvideo-14.bmp b509c3ac24e3543e1f59a7f1456e924d
Which are sourced from the original Xiph PNGs that are all 24-bit.
*EDIT: I change the topic title to reflect the real error being pal8 in ffmpeg as to prevent spreading misinformation about UTVideo. See discussion.