Changes between Initial Version and Version 3 of Ticket #9520


Ignore:
Timestamp:
Nov 23, 2021, 8:07:23 PM (5 years ago)
Author:
Robin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #9520 – Description

    initial v3  
    22ffmpeg is not correctly converting pal8 input to gbrp output. I discovered this when encoding optimized PNGs to UTVideo.
    33
    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.
     4I 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.
    115
    126How to reproduce:
    137{{{
    14 1. Encode the 30 frames to FFV1 and UTVideo:
     81. Confirm both PNGs are identical:
    159
    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
     10ffmpeg -i ref-rgb24.png ref-rgb24.bmp
     11ffmpeg -i opt-pal8.png -vf format=bgr24 opt-pal8.bmp
    2012
    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.
     13You will have to force ffmpeg to convert to BGR24 to match the reference colorspace output. MD5 of both outputs should match 735ee7c8b493855480fd0f5847a66132.
    2214
    23 2. Export all videos and PNGs to BMPs:
     15This means pal8 -> bgr24 conversion is correct and matches the rgb24 -> bgr24 conversion output.
    2416
    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
     172. Force conversion to gbrp before final output:
    3118
    32 3. Perform checksum on all results.
    33 I find all BMPs have the same MD5 checksum except:
     19ffmpeg -i ref-rgb24.png -vf format=gbrp ref-rgb24.bmp
     20ffmpeg -i opt-pal8.png -vf format=gbrp opt-pal8.bmp
    3421
    35 ED_opt_utvideo-12.bmp 02a34fc1e347889d5546b547fa63e6af
    36 ED_opt_utvideo-13.bmp ca40ed9fc4acc827a4a77051433f0102
    37 ED_opt_utvideo-14.bmp e3666199f35234756dddac97b8e18488
     22MD5s 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.
    3823
    39 The above are sourced from the 8-bit optimized PNGs.
     243. Test alternate colorspace path:
    4025
    41 The correct MD5 is as following:
     26ffmpeg -i opt-pal8.png -vf format=bgr0 opt-pal8.bmp
     27ffmpeg -i opt-pal8.png -vf format=bgr0,format=gbrp opt-pal8.bmp
    4228
    43 ED-xiph_utvideo-12.bmp ba5d92ca99726d837859b4b05795d317
    44 ED-xiph_utvideo-13.bmp 735ee7c8b493855480fd0f5847a66132
    45 ED-xiph_utvideo-14.bmp b509c3ac24e3543e1f59a7f1456e924d
     29Both these produce the correct output. Meaning pal -> bgr0 and bgr0 -> gbrp are correct.
     30}}}
     31{{{
     32Another way to confirm this is encoding to UTVideo which uses gbrp colorspace.
    4633
    47 Which are sourced from the original Xiph PNGs that are all 24-bit.
     341. Encode frames to UTVideo:
     35ffmpeg -i ref-rgb24.png -c:v utvideo ref-rgb24.mkv
     36ffmpeg -i opt-pal8.png -c:v utvideo opt-pal8.mkv
     37
     38This encodes the frames to gbrp colorspace.
     39
     402. Decode back to raw BMP:
     41ffmpeg -i ref-rgb24.mkv ref-rgb24.bmp
     42ffmpeg -i opt-pal8.mkv opt-pal8.bmp
     43
     44Checksums are different. ref-rgb24.bmp is correct.
     45
     463. Test alternate colorspace path:
     47ffmpeg -i opt-pal8.png -vf format=bgr0 -c:v utvideo opt-pal8.mkv
     48ffmpeg -i opt-pal8.mkv opt-pal8.bmp
     49
     50Output BMP now has correct checksum.
    4851}}}
    4952
    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.
     53EDIT: Rewrote this whole ticket to simplify it.