[FFmpeg-user] color shift in swscale - slight green tint

Chris Bouchard Chris.Bouchard at framestore.com
Tue Feb 19 12:46:26 CET 2013


I'm getting a colour shift when converting from a 422 pixel format to yuv420p. For example, encoding a grey card (R=128,G=128,B=128) results in a subtle green tint on output (R=126,G=128,B=125). The workaround to avoid color shift is to use " -sws_flags bilinear" or use -sws_flags lanczos+accurate_rnd 

This might be a fault in swscale or the default scaling used 

Default behavior results in color shift . visible as a slight green tint if you encode a plain grey card. 

Green tint apparent: 
ffmpeg -i 18percent_greyPR.mov -pix_fmt yuv420p -f mp4 -vcodec libx264 -crf 23 -s 1280x720 -report default_sws720.mp4 
ffmpeg started on 2013-02-18 at 13:46:14 
Report written to "ffmpeg-20130218-134614.log" 
ffmpeg version N-49601-g8f7e3e6 Copyright (c) 2000-2013 the FFmpeg developers 
built on Feb 13 2013 19:03:28 with gcc 4.4.5 (Debian 4.4.5-12) 
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-libfaac --enable-libxvid 
libavutil 52. 17.101 / 52. 17.101 
libavcodec 54. 91.100 / 54. 91.100 
libavformat 54. 61.104 / 54. 61.104 
libavdevice 54. 3.103 / 54. 3.103 
libavfilter 3. 35.101 / 3. 35.101 
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 '18percent_greyPR.mov': 
Metadata: 
major_brand : qt 
minor_version : 537199360 
compatible_brands: qt 
creation_time : 2013-02-18 12:42:38 
Duration: 00:00:02.08, start: 0.000000, bitrate: 9121 kb/s 
Stream #0:0(eng): Video: prores (apcn / 0x6E637061), yuv422p10le, 1920x1080, 9117 kb/s, 24 fps, 24 tbr, 2400 tbn, 2400 tbc 
Metadata: 
creation_time : 2013-02-18 12:42:38 
handler_name : Apple Alias Data Handler 
[graph 0 input from stream 0:0 @ 0x2195f60] w:1920 h:1080 pixfmt:yuv422p10le tb:1/2400 fr:24/1 sar:0/1 sws_param:flags=2 
[scaler for output stream 0:0 @ 0x218fb80] w:1280 h:720 flags:'0x4' interl:0 
[scaler for output stream 0:0 @ 0x218fb80] w:1920 h:1080 fmt:yuv422p10le sar:0/1 -> w:1280 h:720 fmt:yuv420p sar:0/1 flags:0x4 
[libx264 @ 0x219eb00] using cpu capabilities: MMX2 SSE2Slow SlowCTZ 
[libx264 @ 0x219eb00] profile High, level 3.1 
[libx264 @ 0x219eb00] 264 - core 129 r2245 bc13772 - 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=-2 threads=6 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=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 
Output #0, mp4, to 'default_sws720.mp4': 
Metadata: 
major_brand : qt 
minor_version : 537199360 
compatible_brands: qt 
encoder : Lavf54.61.104 
Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 12288 tbn, 24 tbc 
Metadata: 
creation_time : 2013-02-18 12:42:38 
handler_name : Apple Alias Data Handler 
Stream mapping: 
Stream #0:0 -> #0:0 (prores -> libx264) 
Press [q] to stop, [?] for help 
No more output streams to write to, finishing.=00:00:00.00 bitrate=N/A 
frame= 50 fps= 18 q=-1.0 Lsize= 8kB time=00:00:02.00 bitrate= 34.7kbits/s 
video:7kB audio:0kB subtitle:0 global headers:0kB muxing overhead 19.223889% 
[libx264 @ 0x219eb00] frame I:1 Avg QP:10.32 size: 4236 
[libx264 @ 0x219eb00] frame P:13 Avg QP:12.62 size: 73 
[libx264 @ 0x219eb00] frame B:36 Avg QP:18.67 size: 38 
[libx264 @ 0x219eb00] consecutive B-frames: 4.0% 0.0% 0.0% 96.0% 
[libx264 @ 0x219eb00] mb I I16..4: 95.2% 2.2% 2.5% 
[libx264 @ 0x219eb00] mb P I16..4: 0.2% 0.0% 0.0% P16..4: 0.8% 0.0% 0.0% 0.0% 0.0% skip:99.0% 
[libx264 @ 0x219eb00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0% 0.0% 0.0% direct: 0.0% skip:100.0% L0:25.0% L1:75.0% BI: 0.0% 
[libx264 @ 0x219eb00] 8x8 transform intra:2.2% inter:0.0% 
[libx264 @ 0x219eb00] coded y,uvDC,uvAC intra: 2.8% 0.1% 0.0% inter: 0.0% 0.2% 0.0% 
[libx264 @ 0x219eb00] i16 v,h,dc,p: 95% 1% 5% 0% 
[libx264 @ 0x219eb00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 2% 39% 0% 0% 0% 0% 0% 0% 
[libx264 @ 0x219eb00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 17% 22% 5% 5% 4% 3% 6% 3% 
[libx264 @ 0x219eb00] i8c dc,h,v,p: 100% 0% 0% 0% 
[libx264 @ 0x219eb00] Weighted P-Frames: Y:0.0% UV:0.0% 
[libx264 @ 0x219eb00] kb/s:25.11 

CORRECT COLOUR was achieved by forcing "-sws_flags bilinear" which resulted in: R=127,G=127,B=127 as follows: 

ffmpeg -i 18percent_greyPR.mov -pix_fmt yuv420p -sws_flags bilinear -f mp4 -vcodec libx264 -s 1280x720 -crf 23 -report bilinear_sws720.mp4 
ffmpeg started on 2013-02-18 at 13:47:36 
Report written to "ffmpeg-20130218-134736.log" 
ffmpeg version N-49601-g8f7e3e6 Copyright (c) 2000-2013 the FFmpeg developers 
built on Feb 13 2013 19:03:28 with gcc 4.4.5 (Debian 4.4.5-12) 
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-libfaac --enable-libxvid 
libavutil 52. 17.101 / 52. 17.101 
libavcodec 54. 91.100 / 54. 91.100 
libavformat 54. 61.104 / 54. 61.104 
libavdevice 54. 3.103 / 54. 3.103 
libavfilter 3. 35.101 / 3. 35.101 
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 '18percent_greyPR.mov': 
Metadata: 
major_brand : qt 
minor_version : 537199360 
compatible_brands: qt 
creation_time : 2013-02-18 12:42:38 
Duration: 00:00:02.08, start: 0.000000, bitrate: 9121 kb/s 
Stream #0:0(eng): Video: prores (apcn / 0x6E637061), yuv422p10le, 1920x1080, 9117 kb/s, 24 fps, 24 tbr, 2400 tbn, 2400 tbc 
Metadata: 
creation_time : 2013-02-18 12:42:38 
handler_name : Apple Alias Data Handler 
[graph 0 input from stream 0:0 @ 0x353d1e0] w:1920 h:1080 pixfmt:yuv422p10le tb:1/2400 fr:24/1 sar:0/1 sws_param:flags=2 
[scaler for output stream 0:0 @ 0x352dbc0] w:1280 h:720 flags:'0x2' interl:0 
[scaler for output stream 0:0 @ 0x352dbc0] w:1920 h:1080 fmt:yuv422p10le sar:0/1 -> w:1280 h:720 fmt:yuv420p sar:0/1 flags:0x2 
[libx264 @ 0x353cc80] using cpu capabilities: MMX2 SSE2Slow SlowCTZ 
[libx264 @ 0x353cc80] profile High, level 3.1 
[libx264 @ 0x353cc80] 264 - core 129 r2245 bc13772 - 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=-2 threads=6 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=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 
Output #0, mp4, to 'bilinear_sws720.mp4': 
Metadata: 
major_brand : qt 
minor_version : 537199360 
compatible_brands: qt 
encoder : Lavf54.61.104 
Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 12288 tbn, 24 tbc 
Metadata: 
creation_time : 2013-02-18 12:42:38 
handler_name : Apple Alias Data Handler 
Stream mapping: 
Stream #0:0 -> #0:0 (prores -> libx264) 
Press [q] to stop, [?] for help 
No more output streams to write to, finishing.=00:00:00.00 bitrate=N/A 
frame= 50 fps= 22 q=-1.0 Lsize= 8kB time=00:00:02.00 bitrate= 32.3kbits/s 
video:6kB audio:0kB subtitle:0 global headers:0kB muxing overhead 20.916305% 
[libx264 @ 0x353cc80] frame I:1 Avg QP:15.19 size: 3953 
[libx264 @ 0x353cc80] frame P:13 Avg QP:16.07 size: 49 
[libx264 @ 0x353cc80] frame B:36 Avg QP:19.67 size: 38 
[libx264 @ 0x353cc80] consecutive B-frames: 4.0% 0.0% 0.0% 96.0% 
[libx264 @ 0x353cc80] mb I I16..4: 97.5% 0.0% 2.5% 
[libx264 @ 0x353cc80] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:100.0% 
[libx264 @ 0x353cc80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0% 0.0% 0.0% direct: 0.0% skip:100.0% L0: 0.0% L1:100.0% BI: 0.0% 
[libx264 @ 0x353cc80] 8x8 transform intra:0.0% inter:100.0% 
[libx264 @ 0x353cc80] coded y,uvDC,uvAC intra: 1.7% 0.0% 0.0% inter: 0.0% 0.0% 0.0% 
[libx264 @ 0x353cc80] i16 v,h,dc,p: 97% 1% 2% 0% 
[libx264 @ 0x353cc80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 21% 22% 5% 6% 4% 3% 7% 4% 
[libx264 @ 0x353cc80] i8c dc,h,v,p: 100% 0% 0% 0% 
[libx264 @ 0x353cc80] Weighted P-Frames: Y:0.0% UV:0.0% 
[libx264 @ 0x353cc80] ref B L1: 83.3% 16.7% 
[libx264 @ 0x353cc80] kb/s:22.85 

I also tried lanczos which produced a colour shift. 
I found that only 'bilinear' and 'fast_bilinear' appear to preserve source colour values. If using lanczos I had to also force 'accurate_rnd' to get perfect colour: 

-sws_flags lanczos+accurate_rnd 

Source files was a 10bit ProRes grey card R=128, G=128, B=128 

Colour was measured in Shake, but is visible to human eye as a slight green tint. 

Thanks! 


More information about the ffmpeg-user mailing list