Log in

View Full Version : Pbm with lossless RGB compression


viper_room
9th August 2012, 16:35
I need to compress a series of images with lossless compression. The first two lines of each image contain commands for the display replacing the image bits.
I tried ffv1, x264 and huffyuv (with ffmpeg).

The videos all seem good but only the Huffyuv-compressed video still commands the display.
Huffyuv gives only average results: ~66% compression even though the sequence should be easy (it is the end-credits of a film).
So I'm trying to improve my compression process and I have two questions:

- From the recent post on Comparison of Lossless RGB Encoders Huffyuv should perform better, at least if I have the latest version with good options. From what I found, the latest version (2.1.1) of Huffyuv dates back to 2005 so I guess it is the one included in libavcodec. Is it possible to change the Huffyuv options with ffmpeg?
If I install the Huffyuv codec, how do I use it to compress? I mean, can I use ffmpeg with other codecs than those in libavcodec?

- My second question is not essential to what I'm doing but is so I can sleep well at night.
How it is possible that two lossless versions of the same sequence turn out to be different?
I know that there is no problem with the codecs but there has to be something!
I saw that Huffyuv is keeping the RGB colorspace during the whole compression, I'm sure that x264 doesn't and I have no info about ffv1.
So my most probable hypothesis is that there is a slight loss during the RGB-YUV conversions. But I thought that the YUV-RGB conversion was lossless???

Thanks for your help!

Dark Shikari
9th August 2012, 17:06
x264 has an RGB mode; if you tell it to use RGB, it'll use RGB.

viper_room
9th August 2012, 17:22
I used this command line
x264_32bits.exe --qp 0 --output-csp rgb -o Ed_Cho_x264.mp4 Ed_Cho_huffyuv.avi

And I get a YUV 4:4:4 output (I checked with MPC and MediaInfo)

Is there another option I should have used?

Also, I thought the Integer transform of h.264 had to be done in the YUV colorspace. So I was thinking that x264 would convert from RGB to YUV - compress - convert from YUV to RGB ...

Dark Shikari
9th August 2012, 17:26
"RGB" is just G, B, and R stuffed into the Y, U, and V planes. Those tools are probably reading the colorspace incorrectly. Try ffmpeg.

viper_room
9th August 2012, 17:47
ffmpeg gives
Stream #0:0(und), 8, 1/25: Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), gbrp, 1920x1080, 18202 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc

So it is indeed rgb... (though I don't know the gbrp pixel format)
But then I can't explain why this stream doesn't command the display anymore?

(for the Huffyuv version, ffmpeg give: Stream #0:0, 1, 1/25: Video: huffyuv (HFYU / 0x55594648), bgra, 1920x1080, 25 tbr, 25 tbn, 25 tbc)

MasterNobody
9th August 2012, 18:05
ffmpeg gives
Stream #0:0(und), 8, 1/25: Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), gbrp, 1920x1080, 18202 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc

So it is indeed rgb... (though I don't know the gbrp pixel format)
But then I can't explain why this stream doesn't command the display anymore?

(for the Huffyuv version, ffmpeg give: Stream #0:0, 1, 1/25: Video: huffyuv (HFYU / 0x55594648), bgra, 1920x1080, 25 tbr, 25 tbn, 25 tbc)
Make sure that you use new enough ffmpeg because iirc it doesn't always had direct convertion of gbrp to bgr/bgra formats (without convertion to YUV)

viper_room
10th August 2012, 09:29
Make sure that you use new enough ffmpeg because iirc it doesn't always had direct convertion of gbrp to bgr/bgra formats (without convertion to YUV)

Thanks for the advice, I'm using an automated build from Aug4th so I guess it should be okay.

Sorry to be insistent but does anybody knows if it is possible to chose Huffyuv options with ffmpeg or why the lossless x264 compression modifies the sequence?

jmac698
10th August 2012, 16:26
I never found out how to set the options in ffmpeg, but using the ffdshow gui I can use the ffv1 codec which is actually better, and set large/AC in the options. It also has a version of huffyuv.

viper_room
14th August 2012, 17:51
Thanks for the tip jmac698! Indeed, I gained some Mb...

About why x264 and ffv1 don't send commands to the screen, I think my problem comes from the player because I tried decoding the sequences to raw (uncompressed RGB) and they are exactly identical... So far I've been trying media player classic, vlc and windows media player, so if anybody has an advice about another player, I'll gladly take it!

My guess is it's either that or that my ffdshow filters are not set properly (e.g. the range of RGB levels set to computer monitor instead of TV).
Again, if anybody sees another option, I'm all ears...

poisondeathray
14th August 2012, 18:03
I'm probably missing something obvious .... but

What are these "commands to the screen"?


The first two lines of each image contain commands for the display replacing the image bits.


What do you mean by this? Do you have an example or can you please clarify?

viper_room
15th August 2012, 14:54
Nope, nothing obvious I just didn't explain cause my first post was already pretty long.
I'm displaying these videos on a secondary screen, a LCD TV. What I called "commands to the screen" are instructions describing how I want the backlight of the screen lit up (I'm in public research working on backlight algorithms).
Basically, we replace the RGB values on the first line of pixels on each frame with the instructions.

So far I've tried the following players: MPC-HC, ViPlay3, GOM Player, ffplay, PotPlayer, KMPlayer, Flvplayer and VLC.
GOM Player and Flvplayer simply don't play them.
MPC, VLC and ViPlay3 play Huffyuv version with backlight control but have trouble with x264: no backlight control but also a color-channel switch for MPC and Viplay3 and green screen for VLC.
The other players play both versions visually well but without backlight control...

I tried changing color settings and the output for ffdshow, different video renderers but so far nothing worked.
I'm running out of ideas to try next so please, any idea will be welcome!