Opened 11 years ago

Last modified 11 years ago

#2407 new defect

Conversion from yuv to RGB leads to broken gradients and colors.

Reported by: Björn Sonnenschein Owned by:
Priority: normal Component: swscale
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
If you convert a yuv source to RGB, the image is gets broken up. There appears a slight overall color tint as well as a little change in brightness and depending on the input pixel format heavy banding.

How to reproduce:

ffmpeg -i dnxhd.mov -vcodec libx264 -b:v 100000k -vf format=rgb24 dnxhdconv.mov

ffmpeg version 1.2
built on Mar 25 2013 21:47:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)

Download the example file from here:
http://www.mediafire.com/?3hk4w4v425d7rwb

Use the command and look at the relatively dark, flat sufaces.
You can make a countercheck by using:

ffmpeg -i dnxhd.mov -vcodec libx264 -b:v 100000k -vf format=bgr24 dnxhdconv.mov

Which will not show the problem, so it's not a mathematical issue of rounding values during conversion, but a unique issue of the rgb24 conversion.

This is a dnxd 10-bit file. I have also tested 8 bit limited- and 8 bit fullscale videos and the problem shows up there too, but not that strong.

I will post full terminal output as soon as I get my complete system running. It's broken at the moment.

Attachments (1)

ffv1.avi (1.1 MB ) - added by Björn Sonnenschein 11 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Björn Sonnenschein, 11 years ago

Version: 1.2git-master

Checked on git-master, too.

ffmpeg -i dnxhd.mov -vcodec libx264 -b:v 100000k -vf format=rgb24 dnxhdconv.mov
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 25 2013 21:47:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-frei0r --enable-shared
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dnxhd.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf55.0.100
  Duration: 00:00:00.53, start: 0.018667, bitrate: 178813 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p10le, 1920x1080, 183500 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc
    Metadata:
      handler_name    : DataHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 97 kb/s
    Metadata:
      handler_name    : DataHandler
File 'dnxhdconv.mov' already exists. Overwrite ? [y/N] y
using cpu capabilities: MMX2 SSE2Fast SSEMisalign LZCNT
[libx264 @ 0x1009f60] profile High 4:4:4 Predictive, level 4.1, 4:4:4 8-bit
[libx264 @ 0x1009f60] 264 - core 130 r45 b3065e6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=9 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=100000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to 'dnxhdconv.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf54.63.104
    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv444p, 1920x1080, q=-1--1, 100000 kb/s, 12800 tbn, 25 tbc
    Metadata:                                                                                                                                                                        
      handler_name    : DataHandler                                                                                                                                                  
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 128 kb/s                                                                                                
    Metadata:                                                                                                                                                                        
      handler_name    : DataHandler                                                                                                                                                  
Stream mapping:
  Stream #0:0 -> #0:0 (dnxhd -> libx264)
  Stream #0:1 -> #0:1 (aac -> libfaac)
Press [q] to stop, [?] for help
frame=   13 fps=5.1 q=32766.0 Lsize=    9196kB time=00:00:00.53 bitrate=141249.5kbits/s    
video:9188kB audio:6kB subtitle:0 global headers:0kB muxing overhead 0.018588%
[libx264 @ 0x1009f60] frame I:1     Avg QP: 0.33  size:865603
[libx264 @ 0x1009f60] frame P:3     Avg QP: 0.49  size:796472
[libx264 @ 0x1009f60] frame B:9     Avg QP: 0.69  size:683675
[libx264 @ 0x1009f60] consecutive B-frames:  7.7%  0.0%  0.0% 92.3%
[libx264 @ 0x1009f60] mb I  I16..4: 19.7% 34.6% 45.7%
[libx264 @ 0x1009f60] mb P  I16..4:  9.8% 25.1% 27.0%  P16..4: 12.4% 12.8% 11.0%  0.0%  0.0%    skip: 1.7%
[libx264 @ 0x1009f60] mb B  I16..4:  2.3%  8.0%  2.0%  B16..8: 40.0% 13.1% 11.2%  direct:21.1%  skip: 2.4%  L0:38.5% L1:32.6% BI:28.9%
[libx264 @ 0x1009f60] final ratefactor: -2.14
[libx264 @ 0x1009f60] 8x8 transform intra:45.9% inter:25.7%
[libx264 @ 0x1009f60] coded y,u,v intra: 94.2% 53.6% 65.1% inter: 92.2% 60.7% 70.3%
[libx264 @ 0x1009f60] i16 v,h,dc,p: 22% 16% 51% 11%
[libx264 @ 0x1009f60] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 17% 46%  1%  1%  1%  1%  1%  2%
[libx264 @ 0x1009f60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 24% 21%  4%  5%  6%  5%  4%  5%
[libx264 @ 0x1009f60] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1009f60] ref P L0: 69.9%  5.3% 12.4% 12.4%
[libx264 @ 0x1009f60] ref B L0: 90.7%  8.2%  1.1%
[libx264 @ 0x1009f60] ref B L1: 94.4%  5.6%
[libx264 @ 0x1009f60] kb/s:144739.95

I have to revert the statement that the command

ffmpeg -i dnxhd.mov -vcodec libx264 -b:v 100000k -vf format=bgr24 dnxhdconv.mov

wouldn't show the issue.
In fact I have tried the bgr24 conversion with that command before:

ffmpeg -i dnxhd.mov dnxhdconv.bmp

Output:

ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 25 2013 21:47:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-frei0r --enable-shared
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dnxhd.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf55.0.100
  Duration: 00:00:00.53, start: 0.018667, bitrate: 178813 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p10le, 1920x1080, 183500 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc
    Metadata:
      handler_name    : DataHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 97 kb/s
    Metadata:
      handler_name    : DataHandler
File 'dnxhdconv.bmp' already exists. Overwrite ? [y/N] y
Output #0, image2, to 'dnxhdconv.bmp':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf54.63.104
    Stream #0:0(eng): Video: bmp, bgr24, 1920x1080, q=2-31, 200 kb/s, 90k tbn, 25 tbc
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 -> #0:0 (dnxhd -> bmp)
Press [q] to stop, [?] for help
[image2 @ 0x1211500] Could not get frame filename number 2 from pattern 'dnxhdconv.bmp' (either set updatefirst or use a pattern like %03d within the filename pattern)
av_interleaved_write_frame(): Invalid argument

Which looks good, while doing a conversion to RGB before will look bad.

ffmpeg -i dnxhd.mov -vf format=rgb24 dnxhdconv.bmp
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 25 2013 21:47:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-frei0r --enable-shared
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'dnxhd.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf55.0.100
  Duration: 00:00:00.53, start: 0.018667, bitrate: 178813 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p10le, 1920x1080, 183500 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc
    Metadata:
      handler_name    : DataHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 97 kb/s
    Metadata:
      handler_name    : DataHandler
File 'dnxhdconv.bmp' already exists. Overwrite ? [y/N] y
Output #0, image2, to 'dnxhdconv.bmp':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf54.63.104
    Stream #0:0(eng): Video: bmp, bgr24, 1920x1080, q=2-31, 200 kb/s, 90k tbn, 25 tbc
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 -> #0:0 (dnxhd -> bmp)
Press [q] to stop, [?] for help
[image2 @ 0x7b3500] Could not get frame filename number 2 from pattern 'dnxhdconv.bmp' (either set updatefirst or use a pattern like %03d within the filename pattern)
av_interleaved_write_frame(): Invalid argument

Blender (www.blender.org) also uses libswscale to convert input yuv videos to PIX_FMT_RGBA and so shows the issue, too.

comment:2 by Carl Eugen Hoyos, 11 years ago

If you transcode the first frame of your input file to v210 or ffv1, is the output file sufficient to reproduce the problem when converting to bmp? If yes, please attach the ffv1 (or v210) file.

comment:3 by Björn Sonnenschein, 11 years ago

Hmm, converting the v210 or ffv1 to bmp does not reproduce the problem.
But converting the v210 or ffv1 video to an image format that uses rgb24, for example by using

ffmpeg -i ffv1.avi -vf format=rgb24  ffv1.png

reproduces the issue.

by Björn Sonnenschein, 11 years ago

Attachment: ffv1.avi added

comment:4 by Carl Eugen Hoyos, 11 years ago

Last edited 11 years ago by Carl Eugen Hoyos (previous) (diff)

in reply to:  4 comment:5 by Carl Eugen Hoyos, 11 years ago

Replying to cehoyos:

I tested the following:

Please ignore, I apparently overwrote a file while testing.

comment:6 by Carl Eugen Hoyos, 11 years ago

Do I understand correctly that rgb.bmp shows the problem but bgr.bmp does not?

$ ffmpeg -i ffv1.avi -vf format=rgb24 rgb.bmp
$ ffmpeg -i ffv1.avi -vf format=bgr24 bgr.bmp

and the same for:

$ ffmpeg -i ffv1.avi -vf format=rgb24 rgb.png
$ ffmpeg -i ffv1.avi -vf format=bgr24 bgr.png
Last edited 11 years ago by Carl Eugen Hoyos (previous) (diff)

comment:7 by Björn Sonnenschein, 11 years ago

Yes, that's right.

comment:8 by Carl Eugen Hoyos, 11 years ago

I suspect this is a duplicate of ticket #1582, sorry for not realizing this earlier.

comment:9 by Michael Niedermayer, 11 years ago

please try:
ffmpeg -i ffv1.avi -sws_flags +full_chroma_int -vf format=rgb24 rgb.png

The default C code is not as accurate as the full_chroma_int or the asm code but later exists just for bgr currently

comment:10 by Björn Sonnenschein, 11 years ago

I have tried it and it works. The resulting image is clean!

sun@shine /media/dd624e38-4f22-471f-b835-5d0958a4fbf0/Tests/101TEST_/Schaerfe $ ffmpeg -i ffv1.avi -sws_flags +full_chroma_int -vf format=rgb24 rgb.png
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 25 2013 21:47:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-frei0r --enable-shared
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[avi @ 0x25fe380] non-interleaved AVI
Input #0, avi, from 'ffv1.avi':
  Metadata:
    encoder         : Lavf54.63.104
  Duration: 00:00:00.04, start: 0.000000, bitrate: 223622 kb/s
    Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv422p10le, 1920x1080, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 128 kb/s
File 'rgb.png' already exists. Overwrite ? [y/N] y
Output #0, image2, to 'rgb.png':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0: Video: png, rgb24, 1920x1080, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (ffv1 -> png)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A    
video:2708kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000793%

Last edited 11 years ago by Björn Sonnenschein (previous) (diff)
Note: See TracTickets for help on using tickets.