Transcoding video to work with Java Media Framework (JMF) on Linux

Using the Java Media Framework is an easy way to build java applications that can record, edit, and play videos, but the number of video codec's that it supports is limited. Unless you want to go with a quicktime format, MPEG1 is a good choice (although the files can be a bit large) for portability. When starting with digital video, you can use ffmpeg to convert and encode the video as follows:

ffmpeg -i INPUT_FILENAME.dv -vcodec mpeg1video -an -r 30 OUTPUT_FILENAME.mpg

Using a .mpg file extension is important for JMF to recognize the file. The -an specifies no audio, something you might want to change if you need audio. The -r 30 sets the FPS to 30, which is important if your source video doesn't specify the correct FPS rate. If you want higher quality, use -b 500 or some higher number (default bit rate is 200 kb/sec).

Using H263 

Using MPEG1 (above) allows you to use a 720×480 video with JMF, but the filesize is a bit large. If you want to use H263 (which is also supported by JMF) you can get much smaller file sizes. The only downside is that H263 only allows certain set sizes: 128×96, 176×144, 352×288, 704×576, and 1408×1152, and JMF does not support the two largest sizes, so you are limited to videos of 352×288 maximum size. The command line for this is:

ffmpeg -i INPUT_FILE.dv -y -an -s 352×288 -vcodec h263 OUTPUT_FILE.mov

Here, the -s 352×288 shrinks (or grows) the input file to the correct size. -y tells it to overwrite the OUTPUT_FILE if it already exists. 

Leave a Reply

Your email address will not be published.