Jan 08 2008

Video Encoding

Published by nick at 8:30 pm under My Blog

As you may have noticed I’ve recently started adding video to my website which has added a whole new set of things to do. Hurray. Anyways…just thought I’d share exactly how my video is encoded etc.

Firstly, all my video projects are exported in uncompressed DV avi files, which happen to be very large. These then get encoding to XViD and two different flv files for use on the website. Flv is the video format used by flash video players. Because video encoding takes a long time i’ve setup my server to do it for me over night. My server is an old PII 433mhz box which isn’t ideal for encoding video quickly, but as it’ll be happening over night i don’t really care. I’ve written a simple shell script that takes a source video file and output name(without extension) as arguments, this script then runs mencoder and ffmpeg to encode to XViD and flv.

The script looks like this:

#!/bin/bash

logger “begin encoding xvid of” $1 “. pass 1″

mencoder “$1″ -oac mp3lame -ovc xvid -xvidencopts pass=1:turbo -nosound -o /dev/null

logger “finnished pass1, now pass2 of xvid” $1 ” encoding”

mencoder “$1″ -oac mp3lame -ovc xvid -xvidencopts pass=2:bitrate=3000 -o “$2″-XViD.avi

logger “encoded the xvid of ” $1 ” now starting flv pass 1 encoding”

ffmpeg -i “$1″ -ar 44100 -s 640×480 -vcodec flv -bt 300k -qmin 1 -qmax 10 “$2″_640.flv

logger “encoded large flv of ” $1 ” now doing small version”

ffmpeg -i “$1″ -ar 22050 -s 320×240 -bt 300k -qmin 1 -qmax 10 -vcodec flv “$2″_320.flv

logger “finnished encoding small flv of ” $1 ” now tidying up”

rm -rf divx2pass.log

logger “removed pass logfiles for $1″

Mencoder is responsible for the XViD encoding, and does it with 2 passes to improve quality. The XViDs those commands spit out are very large – i need to refine them somewhat, but at the moment i really can’t be bothered. The ffmpeg series of commands have been tweaked quite a lot to achieve a good quality file that isn’t excessively huge and hence better for streaming. Ffmpeg is only doing single pass encoding, but i am producing two – a large and a small resolution video. Just to make life a little easier for those with slower internet connections. The large videos do require a reasonably fast connection to stream properly.

So yeah, that’s about it. There are a few extra commands in there, the logger ones are there to add lines to the main system log to record progress of the encoding. There’s also a cleanup line to remove the log files for the two pass XViD encoding.

No responses yet

Leave a Reply