-   Linux - Newbie (
-   -   Bash script to convert .mpg files to .avi files? (

Mike_Snyder 09-19-2009 10:20 AM

Bash script to convert .mpg files to .avi files?
I'd like to write a bash script to convert all of the .mpg files in a directory to .avi files. The ffmpeg part of this produces the kind of file that I want, but rather than changing the name of the input and output files each time that I run the script, I'd like to automate it. I've tried this script, but I get an error "command not found". I can't figure out what I'm doing wrong. Please help.

cd /home/michael_s/golf_temp
for i in 'ls *.mpg' ; do

/usr/bin/ffmpeg.exe -i /home/michael_s/golf_temp/"$i" -map 0:0 -map 0:1 -pass 1 -vcodec mpeg4 -vtag xvid -f avi -b 1100k -vol 384 -mbd rd -s 640x480 -aspect 4:3 -acodec libmp3lame -ac 2 -ab 128k /home/michael_s/golf_temp/"$i".avi

rm -f /home/michael_s/golf/temp/"$i".avi

/usr/bin/ffmpeg.exe -i /home/michael_s/golf_temp/"$i" -map 0:0 -map 0:1 -pass 2 -vcodec mpeg4 -vtag xvid -f avi -b 1100k -vol 384 -mbd rd -s 640x480 -aspect 4:3 -acodec libmp3lame -ac 2 -ab 128k /home/michael_s/golf_temp/"$i".avi




Meson 09-19-2009 11:37 AM

First of all, please post your script within [code] [/code] tags for easier reading.

Does your script have excute permissions?


$ chmod u+x
$ ./

Or, does it say this?:

bash: 1: command not found
You have a stray number on line 3

metalx1000 09-19-2009 12:10 PM

Why do you have the ".exe" at the end of ffmpeg?

Mike_Snyder 09-19-2009 12:32 PM

Thanks, guys.

1. The number was just a typo.

2. No, I had not set the script to be executable. :-( I'm new to Linux.

3. I had .exe after ffmpeg because that's what it's called in OS/2, DOS, etc. and that's what I'm accustomed to. The script didn't work with just ffmpeg and the switches, so I changed it trying to make it work.

After fixing the above errors, I now get an error after the script runs ls *.mpg that says, "no such file or directory". That's not true. There are several files in that directory that are listed when I just type ls *.mpg on the command line. I've tried adding the complete path before *.mpg, but get the same error message.

Meson 09-19-2009 12:56 PM

This is the wrong quote character

for i in 'ls *.mpg'; do
You want back-ticks (left of the '1' key):

for i in `ls *.mpg`; do
But really, the more modern thing to do is:

for i in $(ls *.mpg); do

Mike_Snyder 09-19-2009 02:33 PM

Thanks, Meson. It works now.

All times are GMT -5. The time now is 09:52 PM.