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 12th October 2013, 09:58   #1  |  Link
lulalala
Registered User
 
Join Date: Aug 2012
Posts: 11
FFmpeg lossless rgb input/output command

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.
lulalala is offline   Reply With Quote
Old 12th October 2013, 13:55   #2  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
Code:
ffmpeg.exe -i "RGB_source.avi" -c:v libx264 -qp:v 0 -profile:v high444 -pix_fmt yuv444p "444_out.avi"
raffriff42 is offline   Reply With Quote
Old 13th October 2013, 15:16   #3  |  Link
lulalala
Registered User
 
Join Date: Aug 2012
Posts: 11
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
lulalala is offline   Reply With Quote
Old 13th October 2013, 16:30   #4  |  Link
the_weirdo
Yes, I'm weird.
 
the_weirdo's Avatar
 
Join Date: May 2010
Location: Southeast Asia
Posts: 273
[DEL]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.[/DEL]

EDIT: I'm wrong. You can output RGB H.264 with this command line:

Code:
ffmpeg.exe -i %RGB_Source% -c:v libx264rgb -qp 0 -pix_fmt rgb24 %Output%
__________________
“Never argue with stupid people, they will drag you down to their level and then beat you with experience.” — Mark Twain

Last edited by the_weirdo; 13th October 2013 at 17:10.
the_weirdo is offline   Reply With Quote
Old 13th October 2013, 17:01   #5  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,060
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)
poisondeathray is offline   Reply With Quote
Old 13th October 2013, 18:52   #6  |  Link
CoRoNe
Registered User
 
CoRoNe's Avatar
 
Join Date: Nov 2005
Posts: 648
Exactly, the_weirdo:

Code:
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.

Code:
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?
__________________
My hobby website
CoRoNe is offline   Reply With Quote
Old 13th October 2013, 18:58   #7  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,060
EDIT: ahh I see it's libx264rgb , not libx264

Last edited by poisondeathray; 13th October 2013 at 19:01.
poisondeathray is offline   Reply With Quote
Old 13th October 2013, 19:46   #8  |  Link
the_weirdo
Yes, I'm weird.
 
the_weirdo's Avatar
 
Join Date: May 2010
Location: Southeast Asia
Posts: 273
@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").
__________________
“Never argue with stupid people, they will drag you down to their level and then beat you with experience.” — Mark Twain

Last edited by the_weirdo; 13th October 2013 at 19:50. Reason: for some reason, fullrange=on doesn't work with x264opts
the_weirdo is offline   Reply With Quote
Old 13th October 2013, 19:57   #9  |  Link
CoRoNe
Registered User
 
CoRoNe's Avatar
 
Join Date: Nov 2005
Posts: 648
I know, with -x264opts fullrange=on:colormatrix=YCgCo FFMpeg at least doesn't throw in an error, but fullrange=on doesn't do anything.
__________________
My hobby website
CoRoNe is offline   Reply With Quote
Old 13th October 2013, 20:00   #10  |  Link
the_weirdo
Yes, I'm weird.
 
the_weirdo's Avatar
 
Join Date: May 2010
Location: Southeast Asia
Posts: 273
Yes. I've also noticed that. However, it works with -x264-params for some reason.
__________________
“Never argue with stupid people, they will drag you down to their level and then beat you with experience.” — Mark Twain
the_weirdo is offline   Reply With Quote
Old 13th October 2013, 20:27   #11  |  Link
CoRoNe
Registered User
 
CoRoNe's Avatar
 
Join Date: Nov 2005
Posts: 648
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.
__________________
My hobby website
CoRoNe is offline   Reply With Quote
Old 17th October 2013, 03:54   #12  |  Link
lulalala
Registered User
 
Join Date: Aug 2012
Posts: 11
Sorry for the late reply. Thank you! Both
Code:
ffmpeg.exe -i <rgb-source> -pix_fmt bgr24 -c:v libx264rgb -preset veryslow -qp 0 <output>
and
Code:
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 ?
lulalala is offline   Reply With Quote
Old 17th October 2013, 14:19   #13  |  Link
CoRoNe
Registered User
 
CoRoNe's Avatar
 
Join Date: Nov 2005
Posts: 648
BGR24 is the default format. Afaik the difference is only a byte order, but maybe someone more knowledgeable could comment on this.
__________________
My hobby website
CoRoNe is offline   Reply With Quote
Reply

Tags
ffmpeg, lossless, rgb, x264

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:33.


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