Changes between Initial Version and Version 3 of Ticket #9520
- Timestamp:
- Nov 23, 2021, 8:07:23 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #9520 – Description
initial v3 2 2 ffmpeg is not correctly converting pal8 input to gbrp output. I discovered this when encoding optimized PNGs to UTVideo. 3 3 4 Here is the first 30 first frames from Elephants Dream: https://www.mediafire.com/file/knisxsozg41001l/Elephants_Dream_First_30_Frames.7z/file 5 6 The package contains both the original PNGs from Xiph and the optimized PNGs I created with oxipng. The original PNGs are all 24 bit. But the optimized ones are a mixed of 1bit, 8bit and 24bit. 7 8 Copying and pasting my post from doom9 forums: https://forum.doom9.org/showthread.php?t=183452 9 10 I tested the release builds and master branch from gyan and Btbn. 4 I have attached a .7z with two PNGs. One is original PNG from Elephants Dream Frame 13 in RGB24 and the other is optimized PNG in pal8. 11 5 12 6 How to reproduce: 13 7 {{{ 14 1. Encode the 30 frames to FFV1 and UTVideo:8 1. Confirm both PNGs are identical: 15 9 16 ffmpeg -i ED-30-xiph-source\%05d.png -c:v ffv1 ED-xiph_ffv1.mkv 17 ffmpeg -i ED-30-xiph-source\%05d.png -c:v utvideo ED-xiph_utvideo.mkv 18 ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr0 -c:v ffv1 ED-opt_ffv1.mkv 19 ffmpeg -i ED-30-opt\%05d.png -c:v utvideo ED-opt_utvideo.mkv 10 ffmpeg -i ref-rgb24.png ref-rgb24.bmp 11 ffmpeg -i opt-pal8.png -vf format=bgr24 opt-pal8.bmp 20 12 21 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.13 You will have to force ffmpeg to convert to BGR24 to match the reference colorspace output. MD5 of both outputs should match 735ee7c8b493855480fd0f5847a66132. 22 14 23 2. Export all videos and PNGs to BMPs: 15 This means pal8 -> bgr24 conversion is correct and matches the rgb24 -> bgr24 conversion output. 24 16 25 ffmpeg -i ED-30-xiph-source\%05d.png BMP\ED-xiph-%02d.bmp 26 ffmpeg -i ED-30-opt\%05d.png -pix_fmt bgr24 BMP\ED-opt-%02d.bmp 27 ffmpeg -i ED-xiph_ffv1.mkv BMP\ED-xiph_ffv1-%02d.bmp 28 ffmpeg -i ED-xiph_utvideo.mkv BMP\ED-xiph_utvideo-%02d.bmp 29 ffmpeg -i ED-opt_ffv1.mkv BMP\ED-opt_ffv1-%02d.bmp 30 ffmpeg -i ED-opt_utvideo.mkv BMP\ED_opt_utvideo-%02d.bmp 17 2. Force conversion to gbrp before final output: 31 18 32 3. Perform checksum on all results. 33 I find all BMPs have the same MD5 checksum except: 19 ffmpeg -i ref-rgb24.png -vf format=gbrp ref-rgb24.bmp 20 ffmpeg -i opt-pal8.png -vf format=gbrp opt-pal8.bmp 34 21 35 ED_opt_utvideo-12.bmp 02a34fc1e347889d5546b547fa63e6af 36 ED_opt_utvideo-13.bmp ca40ed9fc4acc827a4a77051433f0102 37 ED_opt_utvideo-14.bmp e3666199f35234756dddac97b8e18488 22 MD5s of output BMP will no longer match. ref-rgb24.bmp will match original BMP output from step 1 and opt-pal8.bmp output in this step will be different. 38 23 39 The above are sourced from the 8-bit optimized PNGs. 24 3. Test alternate colorspace path: 40 25 41 The correct MD5 is as following: 26 ffmpeg -i opt-pal8.png -vf format=bgr0 opt-pal8.bmp 27 ffmpeg -i opt-pal8.png -vf format=bgr0,format=gbrp opt-pal8.bmp 42 28 43 ED-xiph_utvideo-12.bmp ba5d92ca99726d837859b4b05795d317 44 ED-xiph_utvideo-13.bmp 735ee7c8b493855480fd0f5847a66132 45 ED-xiph_utvideo-14.bmp b509c3ac24e3543e1f59a7f1456e924d 29 Both these produce the correct output. Meaning pal -> bgr0 and bgr0 -> gbrp are correct. 30 }}} 31 {{{ 32 Another way to confirm this is encoding to UTVideo which uses gbrp colorspace. 46 33 47 Which are sourced from the original Xiph PNGs that are all 24-bit. 34 1. Encode frames to UTVideo: 35 ffmpeg -i ref-rgb24.png -c:v utvideo ref-rgb24.mkv 36 ffmpeg -i opt-pal8.png -c:v utvideo opt-pal8.mkv 37 38 This encodes the frames to gbrp colorspace. 39 40 2. Decode back to raw BMP: 41 ffmpeg -i ref-rgb24.mkv ref-rgb24.bmp 42 ffmpeg -i opt-pal8.mkv opt-pal8.bmp 43 44 Checksums are different. ref-rgb24.bmp is correct. 45 46 3. Test alternate colorspace path: 47 ffmpeg -i opt-pal8.png -vf format=bgr0 -c:v utvideo opt-pal8.mkv 48 ffmpeg -i opt-pal8.mkv opt-pal8.bmp 49 50 Output BMP now has correct checksum. 48 51 }}} 49 52 50 Adding -pix_fmt to the source (before -i) did not fix the issue. Someone on doom9 found that specifying the conversion process to bgr0 (What FFV1 uses) then to UTVideo's gbrp solves the problem: 51 52 ffmpeg -i "PATH\ED-30-opt\%05d.png" -vf format=bgr0,format=gbrp -c:v utvideo ED-opt_bgr0_gbrp_utvideo.mkv 53 54 Which means the pal8 input (which ED_opt_utvideo-12 though 14 are) conversion directly to gbrp has an issue. It is possible other output conversions may have errors as well. 53 EDIT: Rewrote this whole ticket to simplify it.


