Here’s a script to convert a batch of avi files to mpg. I’ve commented out a version of the command which specifies the bitrate, and am using sameq (same quality); you can experiment with the commented out one if that suits your needs better.
#!/bin/sh
for file in *.AVI *.avi
do
echo "Transcoding $file to MPG..."
# ffmpeg -r 30 -b 1600 -i $file $file.mpg
ffmpeg -sameq -i $file $file.mpg
done
Comments (7)
This is not working for me?
It simply spits out the help text for ffmpeg.
Something changed maybe?
thanks
Something is wrong with the CSS of this page. Please delete the above comment
Thanks. Actually I enabled wiki formatting, so the #’s were being converted to bullets. It’s working now tho.
Interesting, but unable to get to work, same results as first commenter. Just prints the help file, along with a statement that the avi file is corrupt or truncated. Any Ideas???
ONe other thing I noticed once the script finished; created new empty file *.avi.mpg Anyway to get rid of the .avi between the file and .mpg?
pass $file thru sed to strip the .avi extension.
for file in *.avi
do
outfile=`echo $file | sed ’s/.avi//’`
ffmpeg -sameq -i $file $outfile.mpg
done
Hi All.
I am a newbie at script writing and I am lost !!!
I understand how to use a text editor and to copy and paste the script into a new file. I don’t understand these things:
1) what do I name the file
2) where do I save the file so that my system (Ubuntu 10.04 LTS) will find it without me needing to type in the full path? Or should I simply save it to my /home folder?
3) what is the command to run the file? I don’t understand how to run .sh files?
Btw — I am old school and I am 48 and been using computers since I was 9 years old. I guess that there is a learning curve when it comes to finding out how to write and run shell scripts. Yes, I am familiar with how batch files work with MS-DOS
Peter
pew@iinet.net.au
All comments gladly welcomed
Hobart, Austraia
Hello,
You can name the file anything you like. Naming them .sh is just a convention, but is not necessary.
The magic is to make the file executable. You can do this via the file manager UI (I’m guessing nautilus, since you are on Gnome) – right click on the file, permissions, allow execute. You can also do this from a terminal – type: chmod +x myscript (where myscript is the name of the file); you can then run it by typing: ./myscript. See http://en.wikipedia.org/wiki/Chmod for more information.
HTH