UNIX Scripts Bash Tips: transcoding converting video files
Being a media whore, I’ve amassed a large collection of video files. All easily viewable using the excellent MPlayer on Linux. The problem has been in making some of them viewable when stuck with Windows.
There is a lot of Windows software out there that can take care of this. Unfortunately, not all of it is compatible on really old hardware. Also, when doing my transcoding using software like VirtualDub, it may not be compatible. For example, Flash (FLV) and Real (RMVB) video files.
After reading the HOWTO Convert video files, I wrote a few bash scripts that use mencoder (of MPlayer) to resolve these problems.
On your console or in a terminal, start up your fave text editor. I tend to use nano on Debian or pico on Slackware.
#!/bin/bash
# convert all FLV to avi in current directory
# xvid for video and PCM for audio
for i in *.flv
do
mencoder -noskip $i -oac pcm -ovc xvid -xvidencopts bitrate=800 -o $i.avi
echo $i processed
done
Be sure to chmod 700 the file to make it private and executable.
On the rare occassion, I’ve found that this script failed to work with some FLV files. Also, I had a lot of audio sync issues in the beginning. That’s why there’s the ” -noskip ” option and use of PCM for audio instead of MP3.
Another script.
#!/bin/bash
# convert a video file (1) to avi (2) using xvid and mp3lame
# video bitrate is 1000 but can be as low as 800
mencoder “$1″ -oac mp3lame -ovc xvid -xvidencopts bitrate=1000 -o $2
In this case, the conversion is not done as a batch job, but one by one. It can be run as so from the command line:
convertscript.sh [name of video file] [name of new video file]
For example,
convertscript.sh day1.rmvb day1.avi
The settings used for the mencode commands above are what I’ve used on Slackware and Debian, so they may differ for your Linux distro.
Mencoder also has options for resizing while keeping the aspect ratio, no audio, and a variety of video and audio options depending upon your MPlayer installation.
Here’s a script I used recently to resize a 1280 pixel wide video which kept crashing my system:
#!/bin/bash
# resize video to 800 pixels wide and keep the aspect ratio
# xvid for video and direct stream copy the audio
mencoder “$1″ -vf scale -zoom -xy 800 -oac copy -ovc xvid -xvidencopts bitrate=1000 -o $2
For example,
convertscript.sh day1-too_big.avi day1-okay.avi

March 25th, 2008 at 12:21 pm
Hello
nice site
March 31st, 2008 at 10:52 pm
Hi
Good site
came on this wonderful site
Very all is simple and with taste.
April 4th, 2008 at 11:08 pm
Hello, excellent site, very rich in content
and correctly carefully thought out,
personally I found here much interesting
and useful
April 7th, 2008 at 9:49 pm
Hello! Excellent site! Searched a long ago