February 1, 2005
Streaming video for free
Recently, I spent a lot of time struggling to get streaming video working properly for my wedding video. I wanted it to be good quality, high compression, require no special software to view, and be accomplished by me using only freely available software. It took me a while to figure out a solution that satisfied all these goals, but I was eventually successful. In the end, I used:
- Darwin Streaming Server (for streaming)
- mencoder (for encoding video)
- faac (for encoding audio)
- mp4creator from MPEG4IP (for multiplexing the stream)
Recent versions of Quicktime player support the MPEG4 format, the new standard for low-bitrate video. This means I could use Darwin streaming server to stream it, and Windows and Mac OSX users can use Quicktime and the associated browser plugin to view it (which most people already have installed). Windows Media Player does not yet seem up to the task of playing standard MPEG4, but hopefully that will come soon.
Once I found the various tools, encoding the video from high-bitrate MPEG2 (coming straight from our DVD master) into MPEG4 was relatively easy. For reference, here is the exact sequence of commands.
stream.mpg is the input MPEG2 video and
wedding_hi.mp4 is the output video that I simply dropped into Darwin Streaming Server's movie directory.
mencoder stream.mpg -vf kerndeint,scale=480:360 -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=600:vhq:v4mv:keyint=132:vpass=1 -nosound \ -frames 143250 -o newstream_hi.avi mencoder stream.mpg -vf kerndeint,scale=480:360 -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=600:vhq:v4mv:keyint=132:vpass=2 -nosound \ -frames 143250 -o newstream_hi.avi ffmpeg -i stream.mpg -vn -f wav out.wav -t 01:19:39.78 faac --mpeg-vers 4 --tns -o out_hi.aac out.wav mp4creator -c newstream_hi.avi -hint wedding_hi.mp4 mp4creator -c out_hi.aac -hint -interleave wedding_hi.mp4 mp4creator -optimize wedding_hi.mp4
I used two-pass encoding with mencoder for maximum quality, but that is optional. Also, you'll note that I needed to trim some garbage from the end of the source video, so the commands to ffmpeg and mencoder use the 'frames' and 't' arguments to restrict the length of the input.
There's also a very complete guide to creating MPEG4 content here.