View Full Version : FFmpeg lossless rgb input/output command
lulalala
12th October 2013, 08:58
I have successfully used x264.exe and avisynth to encode/decode RGB bmp images losslessly, using the following command:
x264 --crf 16 --bframes 0 --colormatrix GBR --qp 0 --preset placebo --range
pc --input-range pc --input-csp rgb --output-csp rgb -o "%2" "%1"
However I want to switch to using FFmpeg.exe to do the encoding (because avisynth does not support unicode). How can I do this? What is ffmpeg's equivalent of the command above?
I have tried this but it does not work:
ffmpeg -i "%1" -c:v libx264 -pix_fmt yuv444p -preset
veryslow -qp 0 "%2"
thanks.
raffriff42
12th October 2013, 12:55
ffmpeg.exe -i "RGB_source.avi" -c:v libx264 -qp:v 0 -profile:v high444 -pix_fmt yuv444p "444_out.avi"
lulalala
13th October 2013, 14:16
Sorry I just tried your solution, but it still shows a difference.
I am wondering if you can take a look. I have packed my test. Running test.bat will do the encoding/decoding/compare and the diff image will be save at o2/diff.bmp
https://mega.co.nz/#!qchAxLBQ!cLt4TE1ggGD6OLilCkkBRgGcTXANIIif7fGkwBIInRc
Thanks a lot
the_weirdo
13th October 2013, 15:30
IIRC, FFmpeg currently doesn't support RGB H.264 output with libx264 yet (correct me if I'm wrong). It'll convert RGB24/BGR24 to YUV444P before feed to libx264, maybe that's why there's a difference.
EDIT: I'm wrong. You can output RGB H.264 with this command line:
ffmpeg.exe -i %RGB_Source% -c:v libx264rgb -qp 0 -pix_fmt rgb24 %Output%
poisondeathray
13th October 2013, 16:01
I don't think ffmpeg libx264 can encode RGB (and you will have lossess during the RGB=>YUV conversion).
You can use use some other lossless RGB codec in ffmpeg eg.. FFV1 or UTvideo which also supports RGB
I was going to suggest piping ffmpeg to x264, but yuv4mpegpipe doesn't support RGB either (not aware of any rgb4mpegpipe)
Reino
13th October 2013, 17:52
Exactly, the_weirdo:
ffmpeg.exe -i <rgb-source> -pix_fmt bgr24 -c:v libx264rgb -preset veryslow -qp 0 <output>
The RGB Matrix coefficients are added automatically, so there's no need to specify that. But...speaking of which, and this might be a bit off-topic, but how can one set those in FFMpeg? RGB as it turns out doesn't need them to be set, but YCgCo does! The only way to set matrix coefficients in FFMpeg that I know of is by using -x264opts colormatrix=YCgCo, but doesn't FFMpeg have such a VUI-option of its own? -colorspace 8 doesn't seem to work at least.
Another thing I'm really puzzled about is how to specify input- and output range as PC with FFMpeg (http://forum.doom9.org/showthread.php?p=1642352#post1642352).
ffmpeg.exe -i <YCgCo-source> -pix_fmt yuv444p -c:v libx264 -preset veryslow -qp 0 -color_range 2 -colorspace 8 <output>
...
Output #0, matroska, to 'D:\rgb_test(ffmpeg,q0,YCgCo).mkv':
Metadata:
encoder : Lavf55.19.100
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p(pc, YCgCo), 640x480, q=-1--1, 1k tbn, 25 tbc
As you can see, as a result of -color_range 2 -colorspace 8, FFMpeg's output even suggests the file would be full-range with a YCgCo VUI-matrix, but in reality will be tv-range and no VUI-matrix, which MadVR detects as BT.601.
Sorry for being off-topic, but am I doing something wrong, or is FFMpeg limited or something?
poisondeathray
13th October 2013, 17:58
EDIT: ahh I see it's libx264rgb , not libx264
the_weirdo
13th October 2013, 18:46
@CoRoNe
It seems that FFmpeg doesn't pass those VUI-options to libx264. You still need to use -x264-params for that (it doesn't recognize "range" option, but you can use "fullrange=on").
Reino
13th October 2013, 18:57
I know, with -x264opts fullrange=on:colormatrix=YCgCo FFMpeg at least doesn't throw in an error, but fullrange=on doesn't do anything.
the_weirdo
13th October 2013, 19:00
Yes. I've also noticed that. However, it works with -x264-params for some reason.
Reino
13th October 2013, 19:27
Haha, you're right! Great find!
That's some strange behaviour. Especially since fullrange isn't a valid x264.exe-command anymore. And I didn't expect there to be any differences between -x264opts and x264-params.
lulalala
17th October 2013, 02:54
Sorry for the late reply. Thank you! Both ffmpeg.exe -i <rgb-source> -pix_fmt bgr24 -c:v libx264rgb -preset veryslow -qp 0 <output> and ffmpeg.exe -i %RGB_Source% -c:v libx264rgb -qp 0 -pix_fmt rgb24 %Output% works.
Just want to ask, is -pix_fmt rgb24 the same as -pix_fmt bgr24 ?
Reino
17th October 2013, 13:19
BGR24 is the default format. Afaik the difference is only a byte order, but maybe someone more knowledgeable could comment on this.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.