Welcome

Mojo
Posts about photography, contract bridge, astrophotography, astronomy, Java development, internet systems.

Making Flash video from AVI files for JAlbum

My wife’s little point-and-shoot Canon SD870 makes some splendid video. The full-res versions are motion-JPEG files stored as an AVI. It doesn’t take very long to eat up a lot of megabytes.

It’s not very practical to share our video on a web site in its raw form. By converting the AVI video to Flash, you can take advantage of modern video compression to make serving the video to friends and family practical and convenient.

(Of course you can always upload the raw file to YouTube and let them do the conversion, but I like owning my content and serving it from my own site. Why prop up Google’s coffers with your content?)

My favorite photo album creator JAlbum will let you drop a Flash video file into a photo album folder. It will do all the set-up with the flash player.

So the first step is to convert your massive raw video into Flash. I use the free open-source command line tool ffmpeg.

FFmpeg is mostly provided with Linux distributions (if you run Linux you may already have it on your machine). If you want to use it on Windows, you have to put in a little extra effort.

This site http://ffmpeg.arrozcru.org/builds/ has ffmpeg builds for windows. Download the latest from the top of their page, ffmpeg-latest.tar.bz2. To unpack it, you’ll need a gnu tar implementation as well, which is available here: http://gnuwin32.sourceforge.net/packages/gtar.htm. (In a future post I’ll provide some suggestions for keeping command line tools and your execution path organized.)

Once you’ve extracted ffmpeg.exe and placed it somewhere on your path, you’ll be able to convert the AVI files to Flash (H.264) video, but the options and documentation for ffmpeg are pretty daunting. It is truly a swiss army knife of media conversion tools.

I spent some time researching recommended encoding parameters intended for typical medium-speed broadband downloads. This article from Adobe had some very good guidelines for selecting encoding parameters for typical web video.

Armed with this information, I am able to generate Flash video .flv files from Canon’s AVI video files. FFmpeg is also useful to extract a still frame from the video to be used as a thumbnail image for JAlbum.

Here is my command line to convert the Canon AVI videos to Flash video suitable for posting:

\path\to\ffmpeg.exe -i %1.AVI -ar 44100 -s 320x240 -r 29.97 -b 575000 -keyint_min 60 -y %1.flv

That’s what I use in a batch file to transcode an AVI file. The %1 is the base filename of the video without the .AVI extension. This sets an audio bitrate of 44,100 bps, a video size of 320×240 (QVGA), a frame rate of 29.97, and a video bitrate of 575 kbps. The “keyframe interval” is the one recommended by the Adobe site above.

The next line of my batch file extracts a frame from the video to use as a thumbnail, and saves it as a JPEG image:

\path\to\ffmpeg.exe -i %1.flv -an -ss 00:00:03 -vframes 1 -y -f image2 %1.jpg

This grabs a frame from three seconds into the video.  If you want a “middle” frame, you’ll have to do the computation on the run time of the video.

(Obviously you need to replace the \path\to part to the actual path to your copy of ffmpeg.exe.)

Those two lines in a batch file are a good start.  I’ll run the batch as, for example:

mkflv.bat MVI_8243

That will leave behind MVI_8243.AVI, MVI_8243.flv, and MVI_8243.jpg.

We’re almost done. When you drag the Flash file into a JAlbum folder, JAlbum will look back in the original directory for a thumbnail image. The thumbnail should be a JPEG file, but it needs to have the file extension of .THM instead of .jpg. So my batch file includes the following two lines as well:

del %1.THM
rename %1.jpg %1.THM

That deletes an existing thumbnail (which is generated by the camera in my case) and replaces it with the ffmpeg extracted frame.

I use the Chameleon skin for JAlbum, and Flash video support might be highly dependent on your skin.

So my family all converged on Atlanta, GA, this past Easter weekend to spend some time together, and naturally it was a great occasion to take a lot of pictures. Jane used her Canon to shoot some fascinating video of a major hail storm that passed through on Friday evening.

I used this technique to transcode the video into Flash, and posted them in the fourth folder of the album. See for yourself how it turned out.

2 comments to Making Flash video from AVI files for JAlbum

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>