[FFmpeg-user] TGA File color looks incorrect when converted to H.264

pdr0 pdr0 at shaw.ca
Wed Apr 7 00:08:26 EEST 2021


Craig L. wrote
> Hi, I am running the following command to convert this red TGA image 
> into a video.
> 
> However, the finished video color does not match the TGA images color.
> 
> Is there something I can do to ensure that the color comes out right?
> 
> I plan on also adding another video stream to this FYI.
> 
> 
> Here is my command:
> 
> /usr/local/bin/ffmpeg -loop 1  -i  FULL.tga  -aspect 1:1    -c:v 
> libx264    -profile:v high -pix_fmt yuv420p -level 5.1  -vsync 1 -async 
> 1  -crf 14   -t 5.000   -r 30    -y  finished.mp4
> 
> 
> Here is a link to download the original image: (Not sure if i could 
> attach it to this email)
> 
> https://drive.google.com/file/d/1V3mZNR7srcUPiNq8dvb4q44oUqhEej6O/view?usp=sharing
> 
> Here is a link to the finished result from the above command.
> 
> https://drive.google.com/file/d/1f3qFLgDKg5kLen1FJzp-C-Xb3yGeHWhc/view?usp=sharing
> 
> 
> 
> Here is the ffmpeg response:
> 
> /usr/local/bin/ffmpeg -loop 1  -i  FULL.tga  -aspect 1:1    -c:v 
> libx264    -profile:v high -pix_fmt yuv420p -level 5.1  -vsync 1 -async 
> 1  -crf 14   -t 5.000   -r 30    -y  finished.mp4
> ffmpeg version 4.3.1-static https://johnvansickle.com/ffmpeg/ Copyright 
> (c) 2000-2020 the FFmpeg developers
>    built with gcc 8 (Debian 8.3.0-6)
>    configuration: --enable-gpl --enable-version3 --enable-static 
> --disable-debug --disable-ffplay --disable-indev=sndio 
> --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r 
> --enable-gnutls --enable-gmp --enable-libgme --enable-gray 
> --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf 
> --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb 
> --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband 
> --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis 
> --enable-libopus --enable-libtheora --enable-libvidstab 
> --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp 
> --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d 
> --enable-libxvid --enable-libzvbi --enable-libzimg
>    libavutil      56. 51.100 / 56. 51.100
>    libavcodec     58. 91.100 / 58. 91.100
>    libavformat    58. 45.100 / 58. 45.100
>    libavdevice    58. 10.100 / 58. 10.100
>    libavfilter     7. 85.100 /  7. 85.100
>    libswscale      5.  7.100 /  5.  7.100
>    libswresample   3.  7.100 /  3.  7.100
>    libpostproc    55.  7.100 / 55.  7.100
> Input #0, image2, from 'FULL.tga':
>    Duration: 00:00:00.04, start: 0.000000, bitrate: 699843 kb/s
>      Stream #0:0: Video: targa, bgr24, 1080x1080, 25 tbr, 25 tbn, 25 tbc
> Stream mapping:
>    Stream #0:0 -> #0:0 (targa (native) -> h264 (libx264))
> Press [q] to stop, [?] for help
> [libx264 @ 0x72b9f00] using SAR=1/1
> [libx264 @ 0x72b9f00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 
> AVX FMA3 BMI2 AVX2 AVX512
> [libx264 @ 0x72b9f00] profile High, level 5.1, 4:2:0, 8-bit
> [libx264 @ 0x72b9f00] 264 - core 161 r3018 db0d417 - H.264/MPEG-4 AVC 
> codec - Copyleft 2003-2020 - 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=34 lookahead_threads=5 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=14.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 
> aq=1:1.00
> Output #0, mp4, to 'finished.mp4':
>    Metadata:
>      encoder         : Lavf58.45.100
>      Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 
> 1080x1080 [SAR 1:1 DAR 1:1], q=-1--1, 30 fps, 15360 tbn, 30 tbc
>      Metadata:
>        encoder         : Lavc58.91.100 libx264
>      Side data:
>        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
> frame=   84 fps=0.0 q=20.0 size=       0kB time=00:00:00.10 bitrate=   
> 3.8kbits/frame=  150 fps=0.0 q=-1.0 Lsize=      10kB time=00:00:04.90 
> bitrate=  17.3kbits/s dup=25 drop=0 speed=6.24x
> video:8kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB 
> muxing overhead: 33.530972%
> [libx264 @ 0x72b9f00] frame I:1     Avg QP: 1.00  size:   273
> [libx264 @ 0x72b9f00] frame P:38    Avg QP: 1.21  size:    53
> [libx264 @ 0x72b9f00] frame B:111   Avg QP: 4.67  size:    45
> [libx264 @ 0x72b9f00] consecutive B-frames:  1.3%  0.0%  0.0% 98.7%
> [libx264 @ 0x72b9f00] mb I  I16..4: 100.0%  0.0%  0.0%
> [libx264 @ 0x72b9f00] 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 @ 0x72b9f00] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 0.0%  
> 0.0%  0.0%  direct: 0.0%  skip:100.0%
> [libx264 @ 0x72b9f00] 8x8 transform intra:0.0%
> [libx264 @ 0x72b9f00] coded y,uvDC,uvAC intra: 0.0% 0.0% 0.0% inter: 
> 0.0% 0.0% 0.0%
> [libx264 @ 0x72b9f00] i16 v,h,dc,p: 99%  0%  1%  0%
> [libx264 @ 0x72b9f00] i8c dc,h,v,p: 100%  0%  0%  0%
> [libx264 @ 0x72b9f00] Weighted P-Frames: Y:0.0% UV:0.0%
> [libx264 @ 0x72b9f00] kb/s:11.58
> 
> _______________________________________________

When you convert between RGB <=> YUV, bt709 matrix is used by convention for
"HD" dimensions. ffmpeg uses bt601 by default unless otherwise specified

The ideal procedure is to use bt709 for the actual conversion, and flag the
file VUI elements as bt709

One way to do this is add
-vf scale=out_color_matrix=bt709,format=yuv420p -x264opts colormatrix=bt709

ffmpeg -loop 1  -r 30  -i  FULL.tga -aspect 1:1  -c:v libx264 -profile:v
high -vf scale=out_color_matrix=bt709,format=yuv420p -x264opts
colormatrix=bt709 -level 5.1  -vsync 1 -async 1  -crf 14  -t 5.000 -y
finished.mp4

It's "normal" for 8bit conversions RGB <=> YUV conversions to be slightly
off (+/- 3 in each channel) . For example if you started with RGB 252,42,41
, you might end up with RGB 252,41,42 or similar from the YUV back to RGB
conversion for display.




--
Sent from: http://ffmpeg-users.933282.n4.nabble.com/


More information about the ffmpeg-user mailing list