You are not logged in.
Pages: 1
Could some kind soul who understands bash scripting well enough explain to me a way to do the fallowing:
I have a directory containing video files, i'd like to convert ALL of them to mkv format with mencoder. The easiest way i can think of would be (if possible) using a small script that lists the contents of the DIR, then runs the command "vs" on each file. vs being an alias i setup for "mencoder -profile default"
Currently i have to do it manually like this:
vs filename-01.avi -o filename-01.mkv
What i'd like to do is have a command or 2 that runs vs on each file one at a time, and has the -o option of the same filename but with mkv in place of avi,
Also can anyone reccomend a good book for learning this sort of thing? I plan on taking a bash scripting course soon, but its been pretty booked for the past few months.
Offline
You will need shopt to use aliases in bash scripts, and you also want *.avi to 'glob'(?) to nothing if there is nothing. So something like this may do:
#! /bin/bash
shopt -s expand_aliases nullglob
for file in *.avi; do
mkvname=$(basename "$file" .avi).mkv
echo Converting "$file" to "$mkvname"
vs "$file" -o "$mkvname"
done
Offline
for f in *.avi; do
vs ${f} -o ${f/.avi/.mkv}
done
Using ${variable/search pattern/replace to} you can do what you want
See:
Advanced Bash-Scripting Guide
http://tldp.org/LDP/abs/html/
Offline
I use that to extract mp3 from flv files, I think it can help you.
# !/bin/sh
for fichier in *.mp3.flv
do
ffmpeg -i "${fichier}" -f mp3 -vn -acodec copy "${fichier/.mp3.flv}".mp3
rm -f "${fichier}"
done
exit 0
all my flv are name something.mp3.flv ,
I search for them, assign one to the "fichier" variable (file in french) and dump them to "${fichier/.mp3/flv}".mp3 --> this takes the original filename, cutting the .mp3.flv and replacing it by mp3, I delete the original, rinse and repeat.
Ah, good taste! What a dreadful thing! Taste is the enemy of creativeness.
Picasso
Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away.
Saint Exupéry
Offline
Thanks to everyone!
I used Procyon's script with a bit of a modification (full mencoder command instead of vs) and just made it /usr/bin/local/vs and removed the alias.
Seems to be working exatly as i wanted.
Interesting thing about the alias not working from the script...didnt know that would happen.
Offline
Pages: 1