You are not logged in.

#1 2009-04-01 01:25:18

evilgold
Member
Registered: 2008-10-30
Posts: 120

yet another scripting question

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

#2 2009-04-01 01:42:50

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: yet another scripting question

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

#3 2009-04-01 01:45:05

big_gie
Member
Registered: 2005-01-19
Posts: 637

Re: yet another scripting question

for f in *.avi; do
    vs ${f} -o ${f/.avi/.mkv}
done

Using ${variable/search pattern/replace to} you can do what you want smile

See:
Advanced Bash-Scripting Guide
http://tldp.org/LDP/abs/html/

Offline

#4 2009-04-01 01:51:14

ChoK
Member
From: France
Registered: 2008-10-01
Posts: 346

Re: yet another scripting question

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

#5 2009-04-01 02:18:20

evilgold
Member
Registered: 2008-10-30
Posts: 120

Re: yet another scripting question

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

Board footer

Powered by FluxBB