Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th September 2022, 08:42   #1  |  Link
Twinbee
Registered User
 
Join Date: Sep 2022
Posts: 2
Wrong output colours using ffmpeg to convert to h264

Hi all, I'm a beginner to ffmpeg (latest 5.1.1 "essentials build" by www.gyan.dev, Windows 10).

Didn't have much luck tracking this down at the Vegas forum or the ffmpeg mailing list, so trying here as a maybe last resort. It's incredibly easy to replicate thankfully. I want to convert numerous frames to make an animation, but I've simplified the problem to using a single image to make a '1 frame video' for the purposes of debugging.

Simply perform this command line with this "original.png" image.:
Code:
ffmpeg.exe -i original.png -crf 0 -vcodec libx264 output.mp4
And this command line On this "doubleHeight" image.:
Code:
ffmpeg.exe -i doubleHeight.png -crf 0 -vcodec libx264 output.mp4
The double height version is darker than it should be. I've checked the resulting video in both Media Player Classic and Chrome.

If you check the dark green colour on the original PNG images, using an eye dropper tool, they're both R=25,G=74,B=15. However, if you check the same colour on the output MP4s, the colour matches on the original PNG, but not the doubleHeight version, which is R=22,G=66,B=12.

If I use -vcodec libx264rgb, instead of -vcodec libx264, that fixes the issue, but I need libx264 so the output video can work on Chrome and other media players. The problem seems to occur in Media Player Classic with a height greater than or equal to 578, and in Chrome with a height greater than or equal to 720.

What gives?

Last edited by Twinbee; 18th September 2022 at 08:56.
Twinbee is offline   Reply With Quote
Old 18th September 2022, 09:10   #2  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
You did not specify a color matrix for the yuv<>rgb conversion thus ffmpeg is guessing based on the resolution.
-> you might want to read up on vui and how to tell ffmpeg which color matrix to use and how to signal it to the output.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 28th September 2022, 20:59   #3  |  Link
Twinbee
Registered User
 
Join Date: Sep 2022
Posts: 2
Thanks. I asked on the ffmpeg mailing list too, and someone recommended both of these. Maybe you'd prefer to use one over the other?

ffmpeg -i input.png -t 5 -vf "zscale=m=709" -c:v libx264 -crf 0 output.mp4

ffmpeg -i input.png -t 5 -color_range tv -colorspace bt470bg -c:v libx264 -crf 0 output.mp4
Twinbee is offline   Reply With Quote
Old 30th September 2022, 20:24   #4  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
a. Whether you use 709 or bt470gb color space should depend on the source.
b. doesn't really matter whether you use zscale or the separate flagging, I often use both.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Reply

Tags
bug, codec, ffmpeg, libx264

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:48.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.