LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mencoder convert script (https://www.linuxquestions.org/questions/linux-newbie-8/mencoder-convert-script-4175490867/)

donjelek 01-10-2014 05:08 PM

mencoder convert script
 
Can please someone help me? . I've got a big list of .rmvb files and i want to convert these files to .avi

I found this command and it works very good:

mencoder <input_movie> -oac mp3lame -ovc lavc -o output_movie.avi

But, i can only use this command for 1 .rmvb file

Does anyone has an idea or example for me to make an (bash? or something else) script to convert the whole list of .rmvb files to .avi files?
And that the script put the converted .avi files in a other directory.

I´ve tried to search with several keywords for an example, but no result. ( maby wrong keywords? hahah )

suicidaleggroll 01-10-2014 05:27 PM

A simple for loop on the command line:
Code:

for i in *.rmvb; do mencoder "$i" -oac mp3lame -ovc lavc -o "/some/other/directory/${i/.rmvb/.avi}"; done
Or if you want a script that can take the files as arguments:
Code:

#!/bin/bash

for i in "$@"; do
  mencoder "$i" -oac mp3lame -ovc lavc -o "/some/other/directory/${i/.rmvb/.avi}"
done


metaschima 01-10-2014 05:33 PM

Try this:

Code:

#!/bin/sh

outputdir="output"

mkdir "$outputdir" || exit 1

for i in *.rmvb
do
        mencoder "$i" -oac mp3lame -ovc lavc -o "$outputdir/$(basename "$i" .rmvb).avi"
done

exit 0

If you set outputdir to "$1" then it will take the output directory name from the command line. If you really do have a list of files then you can use 'while read line' to parse it instead of the for loop.


All times are GMT -5. The time now is 03:27 PM.