Log in

View Full Version : FFMS2 changing RGB values when importing palette-indexed BMP/PNG files


SilSinn9801
18th July 2023, 06:19
I don’t know if this is a bug in VapourSynth R63 or in FFMS2 3.0.1.0 1325+16 6ad7738, but basically when importing (via core.ffms2.Source) indexed BMP or PNG images (that is, images whose pixels don’t store RGB color values but rather indices to a color palette stored in the files’ metadata), some of their pixels’ RGB color values get changed to slightly-different values, even when they’re imported in RGB24 mode (rather than a YUV or YCbCr mode). (This problem does not happen at all with regular RGB24 BMP/PNG files where RGB values are stored directly in the pixels themselves instead of in a palette.)
Attached to this thread is a ZIP with two visually-identical 16×16-pixel BMP files where each pixel is a different shade of gray (out of the 256 values allowed in GRAY8). Y8_index.bmp is the indexed or palettized version (8-bit grayscale palette, 256 indices), while Y8_rgb.bmp is the RGB24-mode version. This is the VPY script I am running to test VapourSynth & FFMS2’s behavior when handling indexed images vs. RGB24 images:
import vapoursynth as vs
from vapoursynth import core

Y8_index = core.ffms2.Source(r'Y8_index.bmp',fpsnum=60,fpsden=1)
Y8_rgb = core.ffms2.Source(r'Y8_rgb.bmp',fpsnum=60,fpsden=1)

FinalVideo = Y8_index*60+Y8_rgb*60
FinalVideo.set_output()
Using VirtualDub2 build 44282 as the VapourSynth visualizer (& Python 3.11), I see that the following 36 RGB values from Y8_index get changed to the following (darker or lighter) values at the output:

#040404 → #030303 (darker)
#0b0b0b → #0a0a0a ("")
#121212 → #111111
#191919 → #181818
#202020 → #1f1f1f
#272727 → #262626
#2e2e2e → #2f2f2f (lighter)
#353535 → #363636 ("")
#3c3c3c → #3d3d3d
#434343 → #444444
#4a4a4a → #4b4b4b
#515151 → #525252
#595959 → #585858 (darker)
#606060 → #5f5f5f ("")
#676767 → #666666
#6e6e6e → #6d6d6d
#757575 → #747474
#7c7c7c → #7b7b7b
#838383 → #848484 (lighter)
#8a8a8a → #8b8b8b ("")
#919191 → #929292
#989898 → #999999
#9f9f9f → #a0a0a0
#a6a6a6 → #a7a7a7
#aeaeae → #adadad (darker)
#b5b5b5 → #b4b4b4 ("")
#bcbcbc → #bbbbbb
#c3c3c3 → #c2c2c2
#cacaca → #c9c9c9
#d1d1d1 → #d0d0d0
#d8d8d8 → #d7d7d7
#dfdfdf → #e0e0e0 (lighter)
#e6e6e6 → #e7e7e7 ("")
#ededed → #eeeeee
#f4f4f4 → #f5f5f5
#fbfbfb → #fcfcfc

poisondeathray
19th July 2023, 01:05
Attachments can take a while to get approved, consider using a 3rd party hosting site like mediafire, google drive , etc..

Did you test any other source filters ? LSmash, ImageMagick ?

StainlessS
19th July 2023, 07:12
How to upload pictures
https://forum.doom9.org/showthread.php?p=1959414

Myrsloik
19th July 2023, 14:25
Or just create issues on github and attach it there. I have vowed to ignore all other types of bug reports.

SilSinn9801
1st August 2023, 07:12
Sorry for late reply (real-life issues + my daily work). Here is the attachment but in Google Drive: https://drive.google.com/file/d/1DcHrmNTfZaDMCuN7_1HLVA2Nr7LVBTBU/view?usp=drive_link

SilSinn9801
1st August 2023, 07:14
I haven’t had time either to test this using a newer version of FFMS2 & see if the issue is a VapourSynth problem or a FFMS2 problem, hence why I specified in my original post the FFMS2 version I used.