View Full Version : Compressibility test with x264
survivor_evil
21st September 2014, 21:46
Hi. Ive been way out of the video compression for several years, back then I used to use gordian knot and AR calculator to run a test on the video and based on the profile settings of the codec (such as bitrate or file size) suggested the best possible resolution for the video. I think I would also suggest the most appropriate bitrate based on the video resolution.
Ive been looking a tool similar to these but current since these two programs are way outdated. I was suggested to use the Constant Quality encode mode of the codec x264 but file size is impossible to determine using this method. Id like a program that based on the bitrate, filesize and length it suggested the best resolution for the video. Id appreciate your help. I use MeGUI, thank you
Asmodian
22nd September 2014, 12:02
From what I understand that methodology has been abandoned because no one has been able to objectively determine the optimal resolution or bits/(pix*frame) accurately. Well, the optimal bits/(pix*frame) is the result when using crf encoding.
Now you can get fairly optimal results simply leaving the video in its native resolution and using x264 in crf mode to specify a quality level or 2-pass to target a size. I would only down scale if I was going for extremely low bit rates and then it would be something simple like one or two standard resolutions down. The range of acceptable bits/pix*frame is wider with x264 compared to Xvid.
hello_hello
22nd September 2014, 13:36
Out of interest, I'd be keen to learn a little more on the subject myself. Not that I select a bitrate/file size when encoding either. These days I generally use x264's CRF (quality) based encoding. However......
From what I remember, AutoGK ran a compression test by running a single pass encode at Q2 over a percentage of the video, with a resolution of 640 x ? (after cropping). After the compression test it'd adjust the resolution accordingly. What I've never known, is how that's calulated.
As far as I know, in AutoGK-terms, (and I guess it applies to Xvid in general), a Q2 encode was 100% quality. For 75% quality, you'd use 75% of the resulting Q2 bitrate. Or, 75% quality was roughly Q2.67 (I think). That part seems easy enough. It's working out how much to adjust the resolution I don't understand. There must be a formula.....
AutoGK would run a compression test by adding something like this to a script. I don't know if the numbers are correct and I think they changed according to the duration, but....
SelectRangeEvery(300, 30)
would encode frames 0 through 29, then 300 through 329 etc, for a total of 10% of the video. The resulting bitrate would be used for the calculations.
In theory you could do something similar with x264. Pick a CRF value, run an encode on 5% to 10% of the video, which would give you an idea of the resulting bitrate for a whole encode. The more you encode when running a compression test, the more accurate it'd be. The ultimate compression test would be a 100% encode. ;) From there you could adjust the CRF value and/or resolution and try again, but there's surely a formula? Unless the way CRF quality is calculated means there's not?
Anyway..... the two programs I can think of which can probably still run a compression test are StaxRip and HDConvertToX. I rarely use StaxRip (we haven't learned to get along yet) but I have the current version on this PC and it will run an x264 compression test when the encoder is in 2 pass mode. I might have a play later to see if I can work out what it's doing by looking at the scripts it creates. StaxRip hasn't been updated in a year but that's probably no big deal. You could update the x264 encoder manually, but has it changed a lot in the last year? I'm fairly sure HDConvertToX will also run an x264 compression test but it hasn't been updated since 2010.
hello_hello
22nd September 2014, 15:25
Well StaxRip certainly seems to do what you want it to do.
You can set your desired CRF value for 100% quality (I used CRF18). There's another "aimed quality" setting which I'm not sure I completely understand yet, but I think it's something to do with how much you can deviate from the set 100% quality. After running a compression test StaxRip adjusts the resizing etc, but you can adjust it manually and StaxRip wil re-calculate the quality, or you can do it the other way around. I put the resizing back to where I wanted it and adjusted the bitrate until StaxRip said the quality would be 100% and ran a 2 pass encode. Then I ran the same encode again, CRF18. The resulting bitrate was very close, only 12kbps difference (I was only testing with a 2 minute video though).
StaxRip ran the compression test this way:
SelectRangeEvery(280,14)
All that makes sense as I used the same resolution for the compression test, the 2 pass encode and the CRF encode so it should be fairly accurate. I haven't tried testing how accurate it's calculations are when adjusting the resizing to achieve a specific quality. Maybe tomorrow when I'm not so tired.
survivor_evil
24th September 2014, 03:59
Well StaxRip certainly seems to do what you want it to do.
You can set your desired CRF value for 100% quality (I used CRF18). There's another "aimed quality" setting which I'm not sure I completely understand yet, but I think it's something to do with how much you can deviate from the set 100% quality. After running a compression test StaxRip adjusts the resizing etc, but you can adjust it manually and StaxRip wil re-calculate the quality, or you can do it the other way around. I put the resizing back to where I wanted it and adjusted the bitrate until StaxRip said the quality would be 100% and ran a 2 pass encode. Then I ran the same encode again, CRF18. The resulting bitrate was very close, only 12kbps difference (I was only testing with a 2 minute video though).
StaxRip ran the compression test this way:
SelectRangeEvery(280,14)
All that makes sense as I used the same resolution for the compression test, the 2 pass encode and the CRF encode so it should be fairly accurate. I haven't tried testing how accurate it's calculations are when adjusting the resizing to achieve a specific quality. Maybe tomorrow when I'm not so tired.
I think I know how it works the "aimed quality option" it is based on the option under it "CRF value defining 100%" the compressibility test will tell you how much quality youre reaching based on what you consider 100% quality. By default the value is 18 so itll depend on what value you use on it.
Using the default presets on x264 i ran a compressibility test on a video and it does not compress it that much at all. In fact, to get a 90% quality it asks me for a bigger file size than the original one. I wonder if getting a 50% quality means visually there wont be that much loss but only on the data (thats the percentage the program recommends). Just like compressing a WAV file to AAC or MP3, theres a lot of data loss but its data we cannot hear so practically theres no loss quality or very little.
Asmodian
24th September 2014, 06:54
This is what crf is for. If you think you should get 50% of crf 18 why not simply use crf 22 (or whatever 50% means).
Pick a preset that is as slow as you can stand. Then raise crf until you start to notice the quality loss, use something a bit lower. Easy to compress video will be smaller and harder to compress video will be larger but it will all meet:
visually there wont be that much loss but only on the data (thats the percentage the program recommends). Just like compressing a WAV file to AAC or MP3, theres a lot of data loss but its data we cannot hear so practically theres no loss quality or very little.
Only it will be the percentage you recommend.
It is very much like VBR encoding for audio in that you don't know the size until after you encode, complex audio is larger than simple audio, and everyone has their own opinion on how much bit-rate is enough.
Edit:
It looks better to encode at crf 22 than it does to downscale until crf 18 is the same size as crf 22.
hello_hello
24th September 2014, 13:28
Using the default presets on x264 i ran a compressibility test on a video and it does not compress it that much at all. In fact, to get a 90% quality it asks me for a bigger file size than the original one. I wonder if getting a 50% quality means visually there wont be that much loss but only on the data (thats the percentage the program recommends). Just like compressing a WAV file to AAC or MP3, theres a lot of data loss but its data we cannot hear so practically theres no loss quality or very little.
For a CRF18 encode it wouldn't be particularly unusual for the resulting bitrate to be higher than the original, if the source is already highly compressed or particularly noisy etc.
When re-encoding cleaner mpeg2 video from DVDs etc it's a different story, only you can achieve similar file sizes with x264 at resolutions such as 754x480 as you might've with Xvid at 656x368 etc and the quality will probably be better.
I hadn't had a chance to play with Staxrip myself again yet, but I will soonish. There's always the Staxrip thread if you need more info on the program, with any luck from someone who knows what they're talking about.
http://forum.doom9.org/showthread.php?t=102652
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.