Ive been struggling with this for quite some time now and made some progress but not quite there yet.
I have two videos generated with Autodesk Maya. The original one (1) "test_scene_GUI.mov" is the one with the correct visual appearance in colors and gamma. It is the one im using as reference.
The other one: (2) "batch_playblast_test_scene_yuv420p.mov" is the one that im trying to figure out how to convert so it looks exactly like (1).
GAMMA CORRECTION TEST
The first thing i noticed was a change in the gamma so i applied this ffmpeg command:
The resulting video is ALMOST quite there in colors and gamma as the (1) but it looks still a little bit washed out, so i thought there might be a problem with the color space.Code:ffmpeg.exe -i batch_playblast_test_scene_yuv420p.mov -vf eq=gamma=2.2 -y batch_playblast_gamma_corrected.mov
COLORSPACE CONVERSION TEST
So, going back to (2) and inspecting it with ffprobe it says that
And since the (1) was obtained in Maya in bt709/sRGB color space i tried to apply the following conversion:
but the resulting video apparently has no difference at all with the input.Code:ffmpeg.exe -i batch_playblast_test_scene_yuv420p.mov -c:v libx264 -x264opts colorprim=bt709:transfer=bt709:colormatrix=bt709 -y test_scene_converted_from_bt470bg.mov
Im kind of lost right now. The (2) was obtained playblasting in standalone in Maya and i was quite convinced the problem was only the gamma but it is not.
What are the steps needed to convert (2) into (1) look?
+ Reply to Thread
Results 1 to 19 of 19
I think the second video only needs a limited range (TV) to full range (PC) adjustment. Note that all commercial and streaming video is limited range. So you may want to do it the other way around.
So i tried this as well:
ffmpeg.exe -i batch_playblast_test_scene_yuv420p.mov -c:v libx264 -vf scale=out_color_matrix=bt709:in_range=limited:out_range=full,eq=gamma=2.2 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -y test_scene_converted_from_bt470bg_color_range.mov
So still lost...
One thing ive noticed is that if you check the following screenshot which shows both .mov files opened with MrViewer.
"test_scene_converted_from_bt470bg_no_gamma.mo v" (shown in "linear" space) and the "test_scene_GUI.mov" (shown in "sRGB" space) look practically identical if you rely on the pinkish tones and violets and forget about the background.
Which is making me think that the only thing i need to do with "test_scene_converted_from_bt470bg_no_gamma.mo v" is convert from sRGB to linear, so that when i open it in MrViewer it matches the original one when set to "sRGB" in the viewing options. I used to think the only difference between linear and sRGB was the gamma 2.2 correction but it seems there is something else.
Ive searched the web for sRGB to linear conversion with ffmpeg and havent found anything useful.
This worked for me:
ffmpeg -i input.mov -vf scale=in_range=limited:out_range=full output.mov
It works for me. The result is near perfect aside from the additional blurring from the YV12 chroma subsampling.
yuy2 jpeg source:
[Attachment 53500 - Click to enlarge]
yv12 after levels adjustment:
[Attachment 53502 - Click to enlarge]
I converted to RGB here assuming pc.601 levels (JPEG is normally full range 601).
I think you have an issue of how the downstream software displays the videos. I recommend you flag the colormatrix and range in the output files to increase your chance or proper playback.
Last edited by jagabo; 25th May 2020 at 10:25.
Try adding the matrix and range options:
ffmpeg -y -i input.mov -vf scale=out_range=full -x264opts colormatrix=bt470bg:fullrange=on output.mov
I was using the other source file "batch_playblast_test_scene_yuv420p.mov".
Tried to flag with different values, but none of them seems to be recognized by the player.
So basically it can all be sorted out with proper video metadata flagging......this is what you are saying right?. but this is again a headache.
If your goal is to create an AVC video for general distribution I'd recommend it be converted and encoded as limited range rec.709, and flagged as such.
At this moment, i think ive understood when the full range conversion must be applied, but to be honest, at this point i still dont know if the video mismatch is due to a shift in the gamma only (which i dont think according to the tests i did (see first post)), a shift in the colorspace not being the same or the problem relies in the viewer options (the colorspace that is applying the viewer when loading the video.. (which i also dont think so because i tried opening it in quicktime, mr viewer and vlc and the overall look in all of them is quite dark as well still, that is wrong))
So, here is what ive done so far and apparently im quite there, i would say almost.
ffmpeg.exe -i batch_playblast_test_scene.mov -vf scale=in_range=limited:out_range=full:out_color_matrix=bt709,eq=gamma=2.2 -pix_fmt yuv420p -crf 18 -y batch_playblast_test_scene_all_in_one.mov
- in_range=limitedut_range=full allows for a full range conversion which is present in the bt470bg original file but not after the conversion to bt709 which is HDTV broadcast limited range. So i need to go back to full range
- out_color_matrix=bt709 applies the color space conversion to HDTV
- eq=gamma=2.2 applies the correct gamma which according to multiple sources is the main difference between sRGB and rec709/bt709 color spaces. Apparently they both share the same primaries.
Here are the two videos original and after conversion
ffmpeg.exe -i batch_playblast_test_scene.mov -vf scale=in_range=limited:out_range=full:out_color_matrix=bt709,eq=gamma=2.2 -color_primaries bt709 -colorspace bt709 -color_trc bt709 -pix_fmt yuv420p -crf 18 -y batch_playblast_test_scene_all_in_one_2048.mov
- color_primaries bt709 -colorspace bt709 -color_trc bt709: these flags are only useful to set the metadata of the video file. They dont actually perform any conversion.
The following line:
ffprobe.exe -show_streams batch_playblast_test_scene_all_in_one_2048.mov
[Attachment 53506 - Click to enlarge]
Still some doubts:
- the ffprobe command output shows "color_range=tv" even after applying theCode:
- Also another thing that is puzzling me is the huge difference in file size: the original one is 5.97MB and ffmpeg converted one is 55.5KB. Maybe there is something still wrong here?
Last edited by Drinkitrinki; 25th May 2020 at 13:59.
And back to your suggestion JAGABO,
here are the two original videos:
with any ffmpeg conversion.
So maybe here the only problem is a matter of the viewing software, because (2) in LINEAR is almost identical to (1) in sRGB. (see screen capture)
[Attachment 53509 - Click to enlarge]
So to sum up, i still dont know where the problem is........