FORUMS: list search recent posts

Improve filesize with same quality?

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Jake Patzke
Improve filesize with same quality?
on Jan 30, 2012 at 4:07:29 pm

Hello!

I am relatively new to FFmpeg, and I am currently using it to convert video recorded by common capture programs (Frapps, etc) for upload to Youtube. The source video is 1080p at roughly 60 GB/hour, encoded with MJPG video and PCM audio. I use these settings to convert:

ffmpeg -i "source.avi" -vcodec libx264 -sameq -acodec libmp3lame -ac 2 -ar 48000 -ab 192k final.avi

One thing I should mention is that I use these settings for multiple people, so that's the main reason I'm using the "-sameq" setting - to ensure the final video is of the same resolution & quality. I record at 1080p, but my friends record at a variety of resolutions.

This works really well, resulting in same-resolution video but at closer to 4 GB/hour. However, because I have a pretty slow upload internet speed, it takes me much longer to upload the video (nearly 6x more) than to encode it.

So, my question: I was wondering if I could trade some more encoding time to get a similar-quality file but with a smaller filesize. In particular, I've heard that two-pass encoding can do this, but the demonstrations I found were difficult to wrap my head around. My current video encoding looks great, but any reduction in filesize would be helpful.

Thanks for your time!


Return to posts index

Michael Rampe
Re: Improve filesize with same quality?
on Feb 1, 2012 at 9:17:04 pm

[Jake Patzke] "I was wondering if I could trade some more encoding time to get a similar-quality file but with a smaller filesize. In particular, I've heard that two-pass encoding can do this, but the demonstrations I found were difficult to wrap my head around."

Tricky question but the answer is "yes" with a but.

Two pass encoding is used to ensure that the quality of the final video is consistent across the range of frames. It does this by analysing the video in the first pass to determine a "best fit" quantiser level that will hit the target bitrate (ie -b). Without a target bitrate (and when target bitrate is not of concern) it has no real benefits.

The other option is to use a different rate control method.
-crf (constant rate factor). Start with a setting of 1 and incrementally increase the number until you get an acceptable quality/filesize ratio. This is very similar to a two pass encode except that you determine the quantiser rather than FFmpeg. It can also be controlled with other methods such as -qmin and -qmax etc.

eg:
$ ffmpeg -i input.mov -c:v libx264 -crf 10 output.mp4

Michael


Return to posts index

Reuben Martin
Re: Improve filesize with same quality?
on Feb 1, 2012 at 9:36:05 pm

Be aware the with CRF mode, 1 is highest quality, 51 is lowest. (That can be a little counter-intuitive)

A crf level of 20 is generally considered the sweet spot for quality vs size.


Return to posts index


Jake Patzke
Re: Improve filesize with same quality?
on Feb 2, 2012 at 2:50:00 pm

Thanks, I did not know that!


Return to posts index

Jake Patzke
Re: Improve filesize with same quality?
on Feb 2, 2012 at 2:51:55 pm

I have heard that since Youtube itself uses constant bitrates (480p, 720p, etc), the CRF method is preferable to VBR two-pass encoding for videos that will be uploaded to that site. Is this true?

Also, if I want my script to process different-resolution video equally well, will a given CRF setting produce similar qualities for 720p and 1080p video, or will one be better?


Return to posts index

Michael Rampe
Re: Improve filesize with same quality?
on Feb 2, 2012 at 9:06:29 pm

[Jake Patzke] "I have heard that since Youtube itself uses constant bitrates (480p, 720p, etc), the CRF method is preferable to VBR two-pass encoding for videos that will be uploaded to that site. Is this true?"

The file produced by two pass target bitrate and one pass CRF are very similar in terms of bitrate distribution.

"Constant bitrate" is a very misunderstood term in regards to interframe compression (rather than intraframe compression). It refers to the rate the video buffer is filled, not necessarily how many bits per second are transferred. Constant bitrate is really only needed (or desired as there are more artifacts) when you are dealing with limitations of some hardware deocoder chips. The nature of I,P,B H.264 in general is variable bitrate.


[Jake Patzke] "Also, if I want my script to process different-resolution video equally well, will a given CRF setting produce similar qualities for 720p and 1080p video, or will one be better?"

Similar qualities. You are basically setting the quantiser level so the 1080p file will be bigger than the 720p file but at a similar quality level.

Anyway, seeing that youtube will reprocess your files anyway, the best option is to give them the highest "constant quality" rather than a constant bitrate (whether or not they use constant bitrate which I am pretty sure they don't anyway).

Michael


Return to posts index


Jake Patzke
Re: Improve filesize with same quality?
on Feb 3, 2012 at 2:52:03 am

Makes sense. Since two-pass looks like a pain, I will play with the CRF command until I get it right. Thanks again for your help!


Return to posts index

Michael Rampe
Re: Improve filesize with same quality?
on Feb 2, 2012 at 9:28:40 pm

and also for reference....

"The decoder's buffer is filled over time at a constant data rate in the case of CBR, and at a non-constant rate in the case of VBR. In both cases, data is removed from the buffer in varying chunks, depending on the actual size of the coded frames.
In the H.264 and VC-1 standards, the VBV is replaced with generalized version called Hypothetical Reference Decoder (HRD)."
http://en.wikipedia.org/wiki/Video_buffering_verifier

And a post from Dark Shikari on the FFmpeg boards (x264 creator) states:
"CBR is when maxrate == bitrate and bufsize is set."

Michael


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]