LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   FFMPEG Mass Conversion Question (https://www.linuxquestions.org/questions/linux-newbie-8/ffmpeg-mass-conversion-question-745240/)

Bonken 08-05-2009 05:03 AM

FFMPEG Mass Conversion Question
 
Hello, i'm a new member here, I hate to start out on a forum by asking a question however I came across this forum and hopefully I can maybe find some help from some Linux experts!

If anyone can help me, it'll be greatly appreciated. I'm currently using the following command to convert my avi's to flv's through my server:

Code:

ffmpeg -i "INPUT.avi" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "OUTPUT.flv"
It's working fine, it takes some time to convert but that's no problem. However i'm converting hundreds of files at a time, so it's very time consuming.

So basically my question is, does anyone know a command to mass convert all files in a certain directory to FLV? Instead of doing them one at a time?

Thanks for any help, and thanks for your time.

James.

vonbiber 08-05-2009 05:13 AM

Quote:

Originally Posted by Bonken (Post 3632024)
I'm currently using the following command to convert my avi's to flv's through my server:

Code:

ffmpeg -i "INPUT.avi" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "OUTPUT.flv"
It's working fine, it takes some time to convert but that's no problem. However i'm converting hundreds of files at a time, so it's very time consuming.

So basically my question is, does anyone know a command to mass convert all files in a certain directory to FLV? Instead of doing them one at a time?

you can write a script

#### beginning of script, cut and paste below this line ####
#!/bin/sh

cd the_directory_where_are_stored your_avi_files

find *.avi | while read f
do
input="$f"
output="${f%.*}.flv"
ffmpeg -i "$input" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "$output"
done

#### end of cut and paste ######

your output files will have the same name as the input file but
a different extension (flv instead of avi)

Bonken 08-05-2009 05:56 AM

Edit: Thanks the script worked, but it only converted one file.

rkirk 08-05-2009 06:23 AM

If the only thing in the directory is the .avi files you want to convert:

Code:

#/usr/bin/env bash

mkdir avifiles

for i in *; do
TEMPNAME=$(echo $i | sed 's/.avi//gI')
# This will strip the ".avi" extension from the name.
ffmpeg -i "$i" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "${TEMPNAME}.flv"
mv "$i" ./avifiles
done

This should convert each file into a .flv file and place the original .avi file into a directory named "avifiles".

Of course, all the usual disclaimers about bashscripts apply, but this is basically a very slight modification to the script I use to convert mp3s to ogg files and move them to my personal music player, so there's no reason it shouldn't work as expected.

Bonken 08-05-2009 06:26 AM

Thanks very much, will try this now.

rkirk 08-05-2009 06:28 AM

Be sure to tell me if it works; I certainly hope so (!) because I know what it's like to require mass conversion of media files.

Bonken 08-05-2009 06:34 AM

Hmm it doesn't seem to be working. I added your code to convert.sh and removed the mkdir line as I already have the directory, however when i'm running the command it's not doing anything:

[root@bonkbox test]# ./convert.sh
[root@bonkbox test]#

rkirk 08-05-2009 06:39 AM

Could you post the entire contents of convert.sh for me? If I look through it as it appears in your script, I might see what the problem is (and I probably know how to fix it, this is the kind of stuff I do all the time, though it's with audio and not video).

Bonken 08-05-2009 06:42 AM

Yep, also thanks for your time, I have limited knowledge at this.

Code:

#/usr/bin/env bash

for i in *; do

    TEMPNAME=$(echo $i | sed 's/.avi//gI') # This will strip the ".avi" extension from the name. ffmpeg -i "$i" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "${TEMPNAME}.flv" mv "$i" ./avifiles

done


rkirk 08-05-2009 06:47 AM

Oh no. There was a typo (I wrote "#/usr[...]" instead of "#!/usr[...]"). This should, now (I've fixed the error).

Tell me if you encounter success (!); again, I try to helpful when I'm actually knowledgable about the topic at hand.

######## BEGIN PASTING (below this line)
#!/usr/bin/env bash

for i in *; do
TEMPNAME=$(echo $i | sed 's/.avi//gI')
# This will strip the ".avi" extension from the name.
ffmpeg -i "$i" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "${TEMPNAME}.flv"
mv "$i" ./avifiles
done
############ END OF PASTE

Bonken 08-05-2009 06:50 AM

Ok it's running, once again thank you VERY much, will update this topic after the test has been complete.

Bonken 08-05-2009 07:15 AM

Seems to be working fine. Thanks so much for your time.

vonbiber 08-05-2009 07:18 AM

Quote:

Originally Posted by Bonken (Post 3632071)
Edit: Thanks the script worked, but it only converted one file.

This is because there must be only one avi file in the
current directory, the other ones are in subfolders.
In that case you must recurse thru all the directories

###modified script
#!/bin/sh

TOP=full_path_to_the_directory_just_above_the_AVI_directory
#replace avi by the actual name of your avi directory
AVI=$TOP/avi
FLV=$TOP/flv

find $AVI/* | while read f
do
if [ -d $f ]; then
continue
fi
cmd="echo $f | sed 's?^$AVI?$FLV?' | sed 's?\.avi?.flv?'"
g="$(eval $cmd)"
d=${g%/*}
ext=${g##*.}
if [ "$ext" == "avi" ]; then
input="$f"
output="$g"
echo "mkdir -p $d"
# mkdir -p $d
echo "ffmpeg -i "$input" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 \"$output\""
# ffmpeg -i "$input" -y -f flv -ar 44100 -ab 64 -ac 1 -acodec mp3 "$output"
fi
done
##########end of script ################

1. remove the echo lines after you tested it
(and then remove the '#' comment below those lines)
2. I'll comment some lines
find $AVI/* | while read f
this will look for every file/folder in the $AVI path, and
store it in the variable f

g="$(eval $cmd)"
this will form the output full path name
d=${g%/*}
this will form the full path to the directory where the output file
must reside

mkdir -p $d
create the target directory if it doesn't already exist

now the conversion command is called if $f is a file and
its extension is avi
the output is written in a similar folder/subfolder and same name
but different extension (flv instead of avi)

Bonken 08-05-2009 08:35 AM

This seems to be working fine, i've thanked both of you through the forum +1 system or what not, cheers guys.


All times are GMT -5. The time now is 05:29 PM.