Friday, February 5, 2010

how to encode videos from dv to flv using open source programs

A few days ago some friends of mine are seeking for the largest audience possible with embedded streaming video and Flash video is a good choice, since it is allegedly supported by 98% of all browsers.

They asked how to put the videos on the website I'm preparing for them starting from their video camera.
Since I'm not sure about the OS they are going to use I tried to find something platform indipendent so that the commands are THE SAME for Linux, mac OS X and windows operating systems.
So let's see:
one can easily create Flash video that can be downloaded progressively with a few open source or other freely available tools. The easiest way to encode the video is with ffmpeg (available through Fink) with something along the lines of:
ffmpeg -i movie.dv -f flv -r 25 -me full -subq 5 -mbd 1 -b 150 -qmin 2 -qmax 31 -s 640x480 -acodec mp3 -ar 22050 -ab 32 -ac 2 video.flv
This will create a Flash video with settings of 25fps, 640 by 480 pixels, 150 video bitrate, and a 32 bitrate stereo audio track.
You can create Flash video that will play nice with slow internet connections by changing the -ab to 8, the -ar to 11025, the -ac to 1 and the -b to 35.  Try to find a value that is ok for you.

Now to make the Flash video support progressive downloading in all the major browsers, we need flvtool2. Once installed, run the following command:
flvtool2 -u video.flv
At this point, all you need is to provide a SWF wrapper for your Flash video. (But this is what I will do for them)


Addendum: Using ffmpeg to encode your Flash video will yield quality about on par with what you could get with shareware product such as video2swf. But even better results can be attained with mencoder. The catch is that you have to compile mencoder from source to get it to work -- a venture ill-advised for the unix-challenged.

In any case, with a newly-compiled mencoder, the following command should work:
mencoder input.dv -ofps 12 -o video.flv -of lavf -lavfopts \
i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc -lavcopts \
acodec=mp3:abitrate=32 -srate 22050 -ovc lavc -lavcopts vcodec=flv:\
vbitrate=100:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:\
vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 \
-vop scale=360:240
You can create Flash video that will play nice with slow internet connections by changing the abitrate to 8, the srate to 11025, and the vbitrate to 35.

hope you enjoy your hot encoded streaming

--
webDesign: http://www.Lxphotostudio.info
 
----------------------------------------------------------------------------------------------------
I started with nothing and I still have most of it.

2 comments:

  1. Hy, I'm a MAcOS user and I tried to install ffmpeg from Fink but ffmpeg in not among stable packages of Fink.
    if you digit "fink selfupdate" this is the Fink reply: "The current selfupdate method is point. Do you wish to change the default
    selfupdate method to rsync? [Y/n] yes
    Failed: Before changing your selfupdate method to 'rsync', you must install XCode, available on your original OS X install disk, or from http://connect.apple.com (after free registration)." and to download it it's necessary to install on your system "

    so I installed XCode from my install disk, then digited "fink selfupdate-rsync" and Fink started to download also unstable packages like ffmpeg and lame.

    Juditta

    ReplyDelete
  2. Hy, I tried to install ffmpeg but in my system (MacOs) I had problems with MacPorts because I needed to install Xquartz. Then I installed succesfully ffmpeg through fink.

    then i tried to convert a VOB file in FLV by this command
    ffmpeg -i VTS_01_1.VOB -f flv -vcodec flv -b 200k -r 25 -s 296x236 -ab 64k -ar 44100 -ac 2 -acodec libmp3lame test.flv

    to have a very small video to upload on the web

    Juditta

    ReplyDelete