« | »

Creating Flash Video in Linux

By Studge | April 14, 2007

Serving videos on your sites can really eat up your bandwidth. This can cost a lot of money, but so can buying Adobe's Flash software just to create videos in their format. It currently sells for about $700.

I personally use MPlayer as my video player of choice in Linux. It has an encoding program call MEncoder that we will use to convert our video. MEncoder should convert any video that MPlayer will play. If you are using Fedora Core, as I do, then you can find both MPlayer and MEncoder in the Fedora repositories. First we need a video to start with. For the purpose of this example we will use this video. It is a short, 2.4MB video of Built To Spill front-man Doug Martsch doing an acoustic version of “Car” somewhere, I do not recall the specific details. The video is DivX 4 with MP3 audio and is 480 x 360 pixels at approximately 15 frames per second. The following command will convert it to the Flash video (FLV) format. NOTE The backslash at the end of each line is used to break up commands in the shell:

[user@localhost ~]$ mencoder testvid.avi \
-ofps 15 -o testvid.flv -of lavf \
-oac mp3lame -lameopts abr:br=64 -srate 22050 -ovc lavc \
-lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -lavcopts \
vcodec=flv:keyint=50:vbitrate=300:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale 320:240

This produces a Flash video that is the same resolution as our source video. One thing you should look out for is matching the frame-rate of your source video. The section in the second line of the command, -ofps 15, tells MEncoder to make the new video have 15 frames per second. You can find your video's frame-rate easily with the file command:

[user@localhost ~]$ file testvid.avi
testvid.avi: RIFF (little-endian) data, AVI, 480 x 360, ~15 fps,
   video: DivX 4, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)

We are also changing the output video's resolution, when we convert it, from 480 x 360 pixels to 320 x 240 pixels. You can omit the last line, -vf scale 320:240, if you do not wish to alter the resolution.

We are finished. You just need to upload your new FLV file to your server and integrate it into your site. I will not cover that process because it will be different for each user dependent upon your particular hosting service and/or CMS. We have managed to reduce the filesize of our video from 2.4MB down to 933.2KB. We have also managed to standardize our video so that it does not depend on the vast array of browser video plugins that our site visitors could be using – just Flash. Here's the video we have produced:


Topics: Linux, Web Development

Share: del.icio.us | digg | reddit

RSS feed | Trackback URI

3 Comments »

Comment by Ashley Sheridan
2008-07-11 06:24:19

I found this really useful and easy to follow. I did have to remove the line that reads
-lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -lavcopts
as this was giving me errors with my mplayer/mencoder install (and I wasn’t too sure what it did anyway.) It might have had something to do with having mplayer/mencoder installed on Windows Vista (I have no choice but to use Windows at work, and I’ve not yet had the chance to test it on my Linux system at home,) but I would have thought that options would be generally the same irrespective of OS.
Thanks for a very useful guide; clear and to the point!

 
Comment by aureliano
2009-08-03 16:12:38

hey,

thx for it. works fine on linux (ubuntu) without this stuff ashley described above.

=))

 
Comment by driver
2009-10-31 18:07:33

you have an error in your scale parameter:
it should be -vf scale=x:y

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.