#9751(swscale:new): Incorrect YUV->RGB24 conversion results on IBM Power9
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+------------------------------------- Reporter: gciaparrone | Type: defect Status: new | Priority: normal Component: swscale | Version: git- | master Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+------------------------------------- Converting a YUV frame into an RGB24 image seems to produce incorrect results on an IBM Power9 processor. Compiling ffmpeg with --disable- altivec solves the issue. The problem might be related to this old issue pointed out by Hong Bo Peng here: https://trac.ffmpeg.org/ticket/7124#comment:7 This can be more easily seen by converting a completely black image from RGB to YUV and then back to RGB on an IBM Power9 (or possibly on any Little Endian processor with ALTIVEC support?). The output image has all pixels set to [16, 16, 16] instead of [0, 0, 0]. The issue spans multiple versions of ffmpeg, including the current git master version. Using --disable-altivec or running the command on a non-ALTIVEC processor outputs the correct image with all [0, 0, 0] pixels. Input image: Output image (IBM Power9): Output image (AMD Ryzen 5 1600X processor): Output image (IBM Power9, --disable-altivec): How to reproduce: {{{ # convert RGB image to YUV420p $ ffmpeg -i black.png -pix_fmt yuv420p black.yuv # convert it back to RGB $ ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -pix_fmt rgb24 reblack.png }}} -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "black.png" added. Original black image -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "reblack.png" added. Black image converted with --disable-altivec -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "reblack_bad.png" added. Black image converted on a IBM Power9 processor -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "reblack_amd.png" added. Black image converted on a AMD processor -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Description changed by gciaparrone: Old description:
Converting a YUV frame into an RGB24 image seems to produce incorrect results on an IBM Power9 processor. Compiling ffmpeg with --disable- altivec solves the issue. The problem might be related to this old issue pointed out by Hong Bo Peng here: https://trac.ffmpeg.org/ticket/7124#comment:7
This can be more easily seen by converting a completely black image from RGB to YUV and then back to RGB on an IBM Power9 (or possibly on any Little Endian processor with ALTIVEC support?). The output image has all pixels set to [16, 16, 16] instead of [0, 0, 0]. The issue spans multiple versions of ffmpeg, including the current git master version. Using --disable-altivec or running the command on a non-ALTIVEC processor outputs the correct image with all [0, 0, 0] pixels.
Input image:
Output image (IBM Power9):
Output image (AMD Ryzen 5 1600X processor):
Output image (IBM Power9, --disable-altivec):
How to reproduce: {{{ # convert RGB image to YUV420p $ ffmpeg -i black.png -pix_fmt yuv420p black.yuv # convert it back to RGB $ ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -pix_fmt rgb24 reblack.png }}}
New description: Converting a YUV frame into an RGB24 image seems to produce incorrect results on an IBM Power9 processor. Compiling ffmpeg with --disable- altivec solves the issue. The problem might be related to this old issue pointed out by Hong Bo Peng here: https://trac.ffmpeg.org/ticket/7124#comment:7 This can be more easily seen by converting a completely black image from RGB to YUV and then back to RGB on an IBM Power9 (or possibly on any Little Endian processor with ALTIVEC support?). The output image has all pixels set to [16, 16, 16] instead of [0, 0, 0]. The issue spans multiple versions of ffmpeg, including the current git master version. Using --disable-altivec or running the command on a non-ALTIVEC processor outputs the correct image with all [0, 0, 0] pixels. Input image: [[Image(black.png)]] Output image (IBM Power9): [[Image(reblack_bad.png)]] Output image (AMD Ryzen 5 1600X processor): [[Image(reblack_amd.png)]] Output image (IBM Power9, --disable-altivec): [[Image(reblack.png)]] How to reproduce: {{{ # convert RGB image to YUV420p $ ffmpeg -i black.png -pix_fmt yuv420p black.yuv # convert it back to RGB $ ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -pix_fmt rgb24 reblack.png }}} -- -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:1> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by Balling): When you convert ffmpeg -i black.png -pix_fmt yuv420p black.yuv you get limited range data with Y set to 16 and Cb, Cb achromatic (128 for 8 bit, 12 bit per pixel yuv420p). Please attach that yuv file for IBM Power9. When you convert back you are IMHO supposed to set input range and because it is somehow gbr use accurate_rnd. ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf scale=in_range=tv:flags=accurate_rnd,format=rgb24 reblack1.png Please test. -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:2> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "reblack1.png" added. Black image converted on IBM Power9 with TV color range setting -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
When you convert ffmpeg -i black.png -pix_fmt yuv420p black.yuv you get
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by gciaparrone): Replying to [comment:2 Balling]: limited range data with Y set to 16 and Cb, Cb achromatic (128 for 8 bit, 12 bit per pixel yuv420p). Please attach that yuv file for IBM Power9.
When you convert back you are IMHO supposed to set input range and
because it is somehow gbr use accurate_rnd.
ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf
scale=in_range=tv:flags=accurate_rnd,format=rgb24 reblack1.png
Please test.
Hi, even with the settings you provided I got the wrong pixels on IBM Power9. Please see the picture attached next. Anyway, shouldn't running the exact same command on two different CPUs produce approximately the same result? -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:3> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by gciaparrone): * Attachment "black.yuv" added. YUV file output on IBM Power9 -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by gciaparrone): I attached the black.yuv file produced on the IBM Power9. It has indeed a limited range on Y. Converting that file to RGB using the standard Altivec-optimized version of ffmpeg produces a "limited range" RGB image, while running the exact command on the Power9 with an ffmpeg version compiled with --disable-altivec produces the correct black image. So there is at least a mismatch in default settings for the two versions, or maybe the Altivec optimized version ignores the color range setting. -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:4> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by Balling): Try ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf scale=in_range=tv:out_range=pc:flags=accurate_rnd,format=rgb24 reblack1.png Also try ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf zscale reblack1.png For last command zimg should be compiled in. Limited range RGB was prohibited in ffmpeg back in 2021, PNG does not support it anyway. -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:5> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by gciaparrone): Replying to [comment:5 Balling]:
Try
ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf scale=in_range=tv:out_range=pc:flags=accurate_rnd,format=rgb24 reblack1.png
This command keeps outputting the wrong image. But I have noticed something weird: the image is not entirely made of [16, 16, 16] pixels. There is a thin band on the bottom of the image with the correct pixels ([0, 0, 0]). This is also true of the original reblack.png image I posted. So something weird is going on.
Also try
ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf zscale
reblack1.png
For last command zimg should be compiled in.
Limited range RGB was prohibited in ffmpeg back in 2021, PNG does not
support it anyway. I will try to recompile ffmpeg as soon as I can and test this out. -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:6> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by gciaparrone): Using the command {{{ ffmpeg -s:v 64x64 -pix_fmt yuv420p -i black.yuv -frames:v 1 -vf zscale reblack1.png }}} outputs an image identical to reblack.png, so the problem persists. I think ffmpeg still re-routes the conversion to the swscale ALTIVEC- optimized code, since the command repeatedly prints {{{ [swscaler @ 0x405049d0] [swscaler @ 0x40cae530] ALTIVEC: Color Space RGB24 }}} -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:7> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: altivec | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Changes (by Carl Eugen Hoyos): * keywords: => altivec -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:8> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: altivec | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by Balling): Is this still a problem? -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:9> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
#9751: Incorrect YUV->RGB24 conversion results on IBM Power9 -------------------------------------+----------------------------------- Reporter: gciaparrone | Owner: (none) Type: defect | Status: new Priority: normal | Component: swscale Version: git-master | Resolution: Keywords: altivec | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+----------------------------------- Comment (by gciaparrone): Replying to [comment:9 Balling]:
Is this still a problem? Unfortunately I currently do not have access to a Power9 CPU, so I cannot verify firsthand if the issue is still present. -- Ticket URL: <https://trac.ffmpeg.org/ticket/9751#comment:10> FFmpeg <https://ffmpeg.org> FFmpeg issue tracker
participants (1)
-
FFmpeg