29 March, 2007

Subversion on Windows - duuuhhhh!

I am most likely one of the less sharp knives in the drawer. As I wrote in another post I can compile ffmpeg using a set of nice instructions someone else has put together. One problem I could not figure out was however that the versions I made were always "SVN-rUnknown". I mentioned that the subversion I was using was the one in Cygwin and it finally dawned on me that the ffmpeg build process needs Subversion to figure out the correct version - and obviously since the MSYS environment had no knowledge of svn it'd be pretty darned difficult to use it. At first
I thought I'd have to build it myself, but luckily I stopped to think. And so I finally understood that the apps in the MSYS environment do not run sort of like in a virtual machine but natively (duhh! kind of like why mingw exists, innit?!?) and that the MSYS shell is just a shell and I should be able to run command line applications from anywhere in the file system. So I just dropped the command line version of Subversion for win32 in a directory and added the path to the bin directory to my PATH environment variable so I could run svn from anywhere - and there was no problem using it in the MSYS shell. Thus I recompiled ffmpeg and hey, presto, now the binary included from which svn version it was built instead of being "Unknown"!

"The wheel is spinning but the hamster is dead"

"Somewhere, a village is missing its idiot"

"The lights are on, but there's no one at home"

These are just some of the things I feel like telling myself. Anyway. Now you know.

Oh yeah, perhaps the biggest "duh" of all is that the instructions linked in the earlier post actually included instructions for installing subversion as well so someone just mindlessly following all the steps would have gotten it right right away... Gaaah! I've got to stop (trying) to think apparently! OTOH, now I finally understood several things that will help me using mingw/MSYS and I hope you do too!

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...

20 March, 2007

Subversive behaviour

Ok, regarding Subversion, I could of course use a windows client (like TortoiseSVN) - which might make more sense (and it is very user-friendly), but I actually had problems with line endings in ./configure after running an update so I don't quite trust it. Might try it again though.

Meanwhile, I'll try to understand what mingw does to make it different from cygwin so I might at some point figure out the compile errors.

19 March, 2007

Transcoding video for Sony Ericsson phones with ffmpeg

I have been playing with ffmpeg on Windows to transcode video for local use on my Sony Ericsson W950i (UIQ3/Symbian-based smartphone) and in the process set up an MSYS/Mingw development environment based on instructions here. I still haven't understood why I can't compile with Cygwin, but I still use the Cygwin environment to update the code with Subversion - since as far as my very limited studies show it's not part of mingw... Feel free to correct me since that is currently all I use Cygwin for and it does take up quite some space!

So, without further ado, here are some working commandlines to get video that works on a Sony Ericsson phone (my input files are mpeg2 files recorded with GBPVR low quality setting, possibly your mileage may vary if you have other types of input files), and also gives reasonable file sizes:
ffmpeg -y -i infile -acodec aac -ab 32k -ar 32000 -vcodec mpeg4 -g 300 -s 320x240 -qscale 10 outfile.mp4

If you want to run the movie on lower powered devices (smaller screen for instance) adapt the size like this:
ffmpeg -y -i infile -acodec aac -ab 32k -ar 32000 -vcodec mpeg4 -g 300 -s qcif -qscale 10 outfile.mp4

The latter line gave a file that played fine on a Sony Ericsson Z1010. To get better sound quality you could use "-ab 64k" instead and then probably lose the "-ar 32000" part for best quality (not sure, but I think so), but don't go higher than that as there are some limitations in the phones when you have video files with audio (which usually is the case with TV recordings). The "-qscale 10" is a parameter you could play with (values are 2-31, 2 is best quality) and for some inputs it's overkill as the default video bit rate of 200 kbps is more than enough to get good quality, It depends on the amount of movement present in the video.

Also, you might want to use two-pass encoding but in my limited experience it doesn't matter much - but it will depend on the original input.

You can output .3gp files (just use a .3gp file extension), but I sometimes have problems with those, so in that case I just run:
mp4box -tmp path-to-temp-dir -add 3gp-file -3gp new-3gp-file

For some reason that often works... Anyway, 3gp files are just mp4 files but without extra information and tracks so you might save a few K, but with my files that is not much so the mp4 format is fine at least for local playback. mp4box does no further transcoding so it has something to do with how the container is written. The reason to use the -tmp flag is to make sure that mp4box' temp files are written to someplace where you have rights to write, otherwise you'll get strange errors ("failed to clone input stream" or some such). If you run with administrative rights you can leave out that flag.

Good luck!