LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2009, 05:03 AM   #1
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Rep: Reputation: 0
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.
 
Old 08-05-2009, 05:13 AM   #2
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Bonken View Post
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)
 
Old 08-05-2009, 05:56 AM   #3
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Edit: Thanks the script worked, but it only converted one file.

Last edited by Bonken; 08-05-2009 at 06:08 AM.
 
Old 08-05-2009, 06:23 AM   #4
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
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.
 
Old 08-05-2009, 06:26 AM   #5
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks very much, will try this now.
 
Old 08-05-2009, 06:28 AM   #6
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
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.
 
Old 08-05-2009, 06:34 AM   #7
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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]#
 
Old 08-05-2009, 06:39 AM   #8
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
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).
 
Old 08-05-2009, 06:42 AM   #9
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 08-05-2009, 06:47 AM   #10
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
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

Last edited by rkirk; 08-05-2009 at 06:48 AM.
 
Old 08-05-2009, 06:50 AM   #11
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Ok it's running, once again thank you VERY much, will update this topic after the test has been complete.
 
Old 08-05-2009, 07:15 AM   #12
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Seems to be working fine. Thanks so much for your time.
 
Old 08-05-2009, 07:18 AM   #13
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by Bonken View Post
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)
 
Old 08-05-2009, 08:35 AM   #14
Bonken
LQ Newbie
 
Registered: Aug 2009
Posts: 8

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg ogg to flv conversion inquisitiveme Linux - Newbie 1 03-10-2009 02:52 PM
Help with ffmpeg conversion, flv player not functioning. Gune Linux - Software 3 01-28-2009 04:01 PM
Green screen after video conversion, AVI to MP4 using Mencoder,Mplayer,FFmpeg,x264, manuken Linux - Newbie 4 10-29-2008 06:40 PM
need ffmpeg mp3 conversion help yajur Programming 18 07-20-2008 05:47 AM
mass dvd conversion, need help and ideas Zedicus Linux - General 1 06-25-2008 05:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration