26 March, 2007

ffmpeg command line example again

Ok, I have this 64MB M2 memory card that is available for video, so therefore I try to compress stuff quite heavily while keeping good quality - I have recorded the first season of Rome (but I missed episode two unfortunately) and after getting rid of the commercials they're about 50 minutes long. With the following (new and improved ;-)) commands I get very nice quality epsiodes that fit snugly onto the 64MB card. With the previous examples I too often got fuzzy faces in particular (even in some close-up scenes) and in the slightly more demanding episodes I still get that, but with these settings I'm fairly happy.

Now, audio could be even more compressed as I'm not too worried about quality when I'm anyway most likely watching in a noisy environment so fine audio details would tend to get lost anyway.

In practice, what I do here is that I write a batch file that converts all .mpg files (in this case) in a directory, and then I redo it for those files that turn out a lot smaller with a better constant quality setting, and for the too big ones with a lower quality. The lines below can be put into a batch file on which you just drop a single file, which is then converted. There's obviously no error handling so don't use without thinking, or you may delete files that you really wanted to keep. If anything at all happens due to your use of this example it is due to your own stupidity or bad luck. I accept no responsibility whatsoever for your use of my example...

@echo off

ffmpeg -y -i %1 -acodec aac -ab 32k -ar 32000 -croptop 72 -cropbottom 56 -vcodec mpeg4 -flags trell -trellis 2 -g 300 -qscale 10 -cmp satd -subcmp satd -mbcmp satd -precmp satd -s 320x192 -pass 1 -passlogfile "%~dpn1" "%~dpn1.mp4"

ffmpeg -y -i %1 -acodec aac -ab 32k -ar 32000 -croptop 72 -cropbottom 56 -vcodec mpeg4 -flags trell -trellis 2 -g 300 -qscale 10 -cmp satd -subcmp satd -mbcmp satd -precmp satd -s 320x192 -pass 2 -passlogfile "%~dpn1" "%~dpn1-final.mp4"

DEL "%~dpn1.mp4"
DEL "%~dpn1-0.log"

PAUSE


A couple of caveats exist of course. The cropping I do before encoding is adapted to the black borders of these particular recordings. You'll have to see what cropping fits best for your files. It only saves a couple of MB per file (for these files) so you might want to skip cropping completely if you're happy with the results anyway. And I should note that regarding the trellis option and flags I really don't know what the effects are since I cannot figure out what values "-trellis" accepts (it's an integer, but that doesn't really tell me anything), and what the relation between "-flags trell" and "-trellis int"is. It might also be interesting to experiment more with these and some others that I believe are related, like "-dia" (the diamond size used as the basis for trellis calculations). But as I am reasonably happy now I'll hold off on the experimentation for a while - anyone feel up for it? Leave a comment...

No comments:

Post a Comment