Log in

View Full Version : How to set both an average quality and a maximum filesize


defaulk9
6th February 2012, 23:01
Hi, I'm trying to automate encoding of a lot of ATSC material, which means that I do not want to do any manual checking of sources to determine their content.

In general, I'm concerned about maintaining a baseline amount of quality in the encodes, but I also don't want the filesize to be too high (anything over half the size of the original file is generally too high for me).

What I've found is that if I set a CRF, I get a decent quality, with file sizes being as low as 13% of the original! This is terrific, but only happens with cartoon content which is apparently highly compressible.

So that's CRF at it's best. At its worst, it's given me file sizes that are slightly higher than the original. I had no idea there would be so much variance here. With that in mind, I'd like a strategy that I can automate (i.e., scriptable), yet lets me limit the filesize to no more than half the original. I could just do 2-pass and set the final size to be half the source, but then I'm wasting a lot of space on the more compressible stuff that I really don't want to.

So are there any recommendations that don't require encoding twice and choosing the smaller file?

Thanks

nm
6th February 2012, 23:35
Hi, I'm trying to automate encoding of a lot of ATSC material, which means that I do not want to do any manual checking of sources to determine their content.

In general, I'm concerned about maintaining a baseline amount of quality in the encodes, but I also don't want the filesize to be too high (anything over half the size of the original file is generally too high for me).

I'd suggest deblocking and denoising if you want good results at that size. Your sources are probably pretty bad compared to Blu-ray, and broadcast bitrates are generally low too, especially for MPEG-2 video.

Make sure you handle interlaced and hard-telecined sources correctly, or at least use some comb detection and encode such sources as interlaced.

So are there any recommendations that don't require encoding twice and choosing the smaller file?

Instead of a normal 1st pass, you could do a full CRF encode while generating the stats file at the same time (--pass 1 --slow-firstpass --crf 20). Then, if the file is too large, simply run a second pass with the bitrate you want: (--pass 2 --bitrate 5000).

This saves the time of one fast firstpass in case of having to do a 2-pass encode.

defaulk9
7th February 2012, 01:38
Make sure you handle interlaced and hard-telecined sources correctly, or at least use some comb detection and encode such sources as interlaced.

I was thinking of using yadif for everything. I'm using a linux box for this and I couldn't find a way of detecting the material. If there's something that can do automatic detection, please tell me. I've been looking.

Instead of a normal 1st pass, you could do a full CRF encode while generating the stats file at the same time (--pass 1 --slow-firstpass --crf 20). Then, if the file is too large, simply run a second pass with the bitrate you want: (--pass 2 --bitrate 5000).

This saves the time of one fast firstpass in case of having to do a 2-pass encode.

Thanks. That's a good idea. Won't be fast for the material that doesn't compress well, but it will save me time that could have been wasted on a first pass. I appreciate it.

nm
7th February 2012, 02:32
I was thinking of using yadif for everything. I'm using a linux box for this and I couldn't find a way of detecting the material. If there's something that can do automatic detection, please tell me. I've been looking.

HandBrake has a decomb (https://trac.handbrake.fr/wiki/Decomb) filter that does this. If you are satisfied with same-framerate deinterlacing by yadif, it's a good option. Or better than plain yadif at least. HandBrake has a CLI frontend, and I think it also gained support for x264 presets and tunings recently (in SVN).

Personally I wouldn't use yadif since it ruins fine details and increases bitrate requirements. Yadif+mcdeint is tolerable, if you don't want to run AviSynth in Wine. I posted more deinterlacing tips for MPlayer/MEncoder/ffmpeg here: http://forum.doom9.org/showthread.php?p=1555481#post1555481

Encoding as interlaced is a good alternative too. Then you can use better deinterlacers in the future, and don't need to worry about field blending and hard telecine at this point. Since your source material is 1080i30 (?), some form of 3:2 pulldown is used very often.