#658 closed enhancement (fixed)
auto-select yuv420p for RGB inputs with libx264
| Reported by: | llogan | Owned by: | |
|---|---|---|---|
| Priority: | important | Component: | avcodec |
| Version: | git-master | Keywords: | |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | yes | |
| Analyzed by developer: | no |
Description
I've noticed an increasing number of users wondering why their outputs are not playing normally in some video players, and/or why some profiles won't work ("main profile doesn't support 4:4:4" for example). The general answer is to tell them to use "-pix_fmt yuv420p". x264 technically supports RGB, but I think the vast majority of users will want YUV, although they may not know it.
We closed a few similar reports as invalid (#585 and #601) because the current behavior isn't wrong, but it is inconsistent, but now that I see more questions about this I think the default behavior should be changed.
Current behavior:
$ ffmpeg -t 5 -loop 1 -i rgb24.png -vcodec libx264 -preset medium -crf 24 -y output.mp4
ffmpeg version N-34884-g7575980, Copyright (c) 2000-2011 the FFmpeg developers
built on Nov 15 2011 11:51:13 with gcc 4.6.2
configuration: --prefix=/usr --enable-gpl --enable-libx264
libavutil 51. 25. 0 / 51. 25. 0
libavcodec 53. 34. 0 / 53. 34. 0
libavformat 53. 20. 0 / 53. 20. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 48. 1 / 2. 48. 1
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
[image2 @ 0x2566880] max_analyze_duration 5000000 reached at 5000000
Input #0, image2, from 'rgb24.png':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, rgb24, 1000x1000, 25 fps, 25 tbr, 25 tbn, 25 tbc
[buffer @ 0x2566800] w:1000 h:1000 pixfmt:rgb24 tb:1/1000000 sar:0/1 sws_param:
[libx264 @ 0x256fe80] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x256fe80] profile High 4:4:4 Predictive, level 3.2, 4:4:4 8-bit
[libx264 @ 0x256fe80] 264 - core 119 r2106 07efeb4 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - 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=12 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=crf mbtree=1 crf=24.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
Metadata:
encoder : Lavf53.20.0
Stream #0:0: Video: h264 (![0][0][0] / 0x0021), rgb24, 1000x1000, q=-1--1, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (png -> libx264)
Press [q] to stop, [?] for help
frame= 125 fps= 96 q=-1.0 Lsize= 30kB time=00:00:04.92 bitrate= 49.2kbits/s
video:27kB audio:0kB global headers:0kB muxing overhead 10.153522%
[libx264 @ 0x256fe80] frame I:1 Avg QP:18.84 size: 18603
[libx264 @ 0x256fe80] frame P:31 Avg QP:31.06 size: 117
[libx264 @ 0x256fe80] frame B:93 Avg QP:31.85 size: 49
[libx264 @ 0x256fe80] consecutive B-frames: 0.8% 0.0% 0.0% 99.2%
[libx264 @ 0x256fe80] mb I I16..4: 88.5% 5.3% 6.2%
[libx264 @ 0x256fe80] mb P I16..4: 1.8% 0.0% 0.0% P16..4: 0.1% 0.0% 0.0% 0.0% 0.0% skip:98.1%
[libx264 @ 0x256fe80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.3% 0.0% 0.0% direct: 0.0% skip:99.7% L0:66.9% L1:33.1% BI: 0.0%
[libx264 @ 0x256fe80] 8x8 transform intra:3.8% inter:36.5%
[libx264 @ 0x256fe80] coded y,u,v intra: 2.3% 2.2% 2.3% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x256fe80] i16 v,h,dc,p: 77% 23% 0% 0%
[libx264 @ 0x256fe80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 54% 3% 43% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x256fe80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 27% 18% 2% 2% 2% 2% 2% 1%
[libx264 @ 0x256fe80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x256fe80] ref P L0: 51.7% 7.9% 37.1% 3.4%
[libx264 @ 0x256fe80] ref B L0: 32.4% 65.3% 2.3%
[libx264 @ 0x256fe80] ref B L1: 98.3% 1.7%
[libx264 @ 0x256fe80] kb/s:42.84
Re-encoding the output with same settings. Note auto-selecting format 'yuv420p':
$ ffmpeg -i output.mp4 -vcodec libx264 -preset medium -crf 24 -y out2.mp4
ffmpeg version N-34884-g7575980, Copyright (c) 2000-2011 the FFmpeg developers
built on Nov 15 2011 11:51:13 with gcc 4.6.2
configuration: --prefix=/usr --enable-gpl --enable-libx264
libavutil 51. 25. 0 / 51. 25. 0
libavcodec 53. 34. 0 / 53. 34. 0
libavformat 53. 20. 0 / 53. 20. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 48. 1 / 2. 48. 1
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
encoder : Lavf53.20.0
Duration: 00:00:05.00, start: 0.000000, bitrate: 48 kb/s
Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), gbr24p, 1000x1000, 43 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name :
Incompatible pixel format 'gbr24p' for codec 'libx264', auto-selecting format 'yuv420p'
[buffer @ 0x1cf1280] w:1000 h:1000 pixfmt:gbr24p tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x1cf1680] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'out'
[scale @ 0x1cf1b60] w:1000 h:1000 fmt:gbr24p -> w:1000 h:1000 fmt:yuv420p flags:0x4
[libx264 @ 0x1cfd920] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x1cfd920] profile High, level 3.2
[libx264 @ 0x1cfd920] 264 - core 119 r2106 07efeb4 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - 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=12 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=crf mbtree=1 crf=24.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
encoder : Lavf53.20.0
Stream #0:0(und): Video: h264 (![0][0][0] / 0x0021), yuv420p, 1000x1000, q=-1--1, 25 tbn, 25 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
handler_name :
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Press [q] to stop, [?] for help
frame= 125 fps= 85 q=-1.0 Lsize= 21kB time=00:00:04.92 bitrate= 35.3kbits/s
video:18kB audio:0kB global headers:0kB muxing overhead 14.750026%
[libx264 @ 0x1cfd920] frame I:1 Avg QP:16.37 size: 12481
[libx264 @ 0x1cfd920] frame P:32 Avg QP:25.74 size: 65
[libx264 @ 0x1cfd920] frame B:92 Avg QP:28.95 size: 40
[libx264 @ 0x1cfd920] consecutive B-frames: 1.6% 0.0% 2.4% 96.0%
[libx264 @ 0x1cfd920] mb I I16..4: 93.1% 0.1% 6.9%
[libx264 @ 0x1cfd920] mb P I16..4: 0.1% 0.0% 0.0% P16..4: 0.1% 0.0% 0.0% 0.0% 0.0% skip:99.8%
[libx264 @ 0x1cfd920] 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:36.1% L1:63.9% BI: 0.0%
[libx264 @ 0x1cfd920] 8x8 transform intra:0.0% inter:57.9%
[libx264 @ 0x1cfd920] coded y,uvDC,uvAC intra: 4.8% 10.6% 8.5% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x1cfd920] i16 v,h,dc,p: 84% 15% 2% 0%
[libx264 @ 0x1cfd920] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 75% 12% 12% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x1cfd920] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 28% 19% 2% 1% 2% 2% 1% 1%
[libx264 @ 0x1cfd920] i8c dc,h,v,p: 62% 21% 17% 1%
[libx264 @ 0x1cfd920] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x1cfd920] ref P L0: 66.7% 1.7% 25.8% 5.8%
[libx264 @ 0x1cfd920] ref B L0: 78.6% 14.3% 7.1%
[libx264 @ 0x1cfd920] ref B L1: 94.9% 5.1%
[libx264 @ 0x1cfd920] kb/s:29.14
Also, default behavior of x264 is to choose yuv420p:
$ x264 rgb24.png -o output.h264 Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. lavf [info]: 1000x1000p 0:1 @ 25/1 fps (vfr) resize [warning]: converting from rgb24 to yuv420p x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 x264 [info]: profile High, level 3.2 [swscaler @ 0x2f16820] Warning: data is not aligned! This can lead to a speedloss x264 [info]: frame I:1 Avg QP:25.53 size: 7473 x264 [info]: mb I I16..4: 88.8% 5.4% 5.8% x264 [info]: 8x8 transform intra:5.4% x264 [info]: coded y,uvDC,uvAC intra: 3.6% 8.4% 2.7% x264 [info]: i16 v,h,dc,p: 79% 19% 2% 0% x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 2% 0% 98% 0% 0% 0% 0% 0% 0% x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 43% 27% 20% 1% 2% 2% 2% 2% 2% x264 [info]: i8c dc,h,v,p: 78% 9% 12% 1% x264 [info]: kb/s:1494.60 encoded 1 frames, 25.58 fps, 1494.60 kb/s
Change History (7)
comment:1 by , 14 years ago
| Component: | undetermined → avcodec |
|---|---|
| Priority: | wish → important |
| Reproduced by developer: | set |
| Status: | new → open |
comment:2 by , 14 years ago
Does a private option make more sense than just setting an appropriate pix_fmt to preserve RGB? With x264 I believe "--output-csp rgb" keeps RGB:
$ x264 rgb24.png --output-csp rgb -o output.h264 Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. lavf [info]: 1000x1000p 0:1 @ 25/1 fps (vfr) x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 x264 [info]: profile High 4:4:4 Predictive, level 3.2, 4:4:4 8-bit x264 [info]: frame I:1 Avg QP:26.66 size: 11440 x264 [info]: mb I I16..4: 84.3% 10.3% 5.4% x264 [info]: 8x8 transform intra:10.3% x264 [info]: coded y,u,v intra: 2.8% 2.8% 4.1% x264 [info]: i16 v,h,dc,p: 80% 20% 0% 0% x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 5% 5% 90% 0% 0% 0% 0% 0% 0% x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 26% 19% 1% 2% 2% 2% 2% 2% x264 [info]: kb/s:2288.00 encoded 1 frames, 20.00 fps, 2288.00 kb/s
comment:3 by , 14 years ago
i dont think this can be done with a private option (but it would be nice otherwise), a seperate AVCodec would work though, like x264rgb
comment:5 by , 14 years ago
| Resolution: | → fixed |
|---|---|
| Status: | open → closed |
Locally fixed through a 2nd AVCodec
comment:7 by , 10 years ago
for followers, you can specify it like "ffmpeg -i input -c:v libx264rgb" (and add normal libx264 args after that).



I believe this should at least be discussed, a possible solution would be a private option that "allows" rgb.