Register
It is currently Mon Sep 01, 2014 1:36 am

Multiple file conversion with ffmpeg


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Oct 01, 2008 9:05 am   

Joined: Wed Oct 01, 2008 8:57 am
Posts: 3
Hi everyone.

I am trying to write a simple script to recode all the .mp3 files in a folder to 160k using ffmpeg. I have one little problem, I would like the output file to be the same as the input file (rewrite) so ffmpeg warns you about this and asks you for confirmation (y/N). Is there a way to automatically "echo a y and an enter" (sorry for the poor explanation) for every question it asks? I have tryied the yes command but it infinitely prints y and the loop won't finish. This is the code I have written so far.

Code:
for f in *.mp3; do
   ffmpeg -i $f -ab 160k $f
done


Is it possible to do something like this:

Code:
ffmpeg -i $f -ab 160k $f & echo -e "y \r"


I guess the trick is in the piping/redirection... is the & correct? I know I can avoid this problem simpli not rewriting the original file, but I am curious and would like to enlighten my mind a bit. Thanks. :)


Top
 Profile  
 PostPosted: Wed Oct 01, 2008 7:59 pm   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
Use echo y | foo to connect echo's stdout to foo's stdin


Top
 Profile  
 PostPosted: Thu Oct 02, 2008 5:16 am   

Joined: Wed Oct 01, 2008 8:57 am
Posts: 3
Thanks Daenyth, I thought that would work, but it does not. ffmpeg stops and only encodes a few kilobytes.


Top
 Profile  
 PostPosted: Thu Oct 02, 2008 5:19 am   

Joined: Wed Oct 01, 2008 8:57 am
Posts: 3
Well, it turns out I am a bit stupid :D

If I am overwriting the original mp3 file, there is nowhere to read from to continue the conversion! It is not a BASH problem, it is a basic computing fact...

Thank you :wink:


Top
 Profile  
 PostPosted: Thu Oct 02, 2008 10:29 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
could do something nice like:
Code:
for f in *.mp3; do
   ffmpeg -i "$f" -ab 160k tmp.file
   mv tmp.file "$f"
done


Top
 Profile  
 PostPosted: Tue Nov 18, 2008 10:04 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
You can also use a redirection for this.

for i in *.mp3; do
ffmpeg -i "$f" -ab 160k "$f" <<EOF
y
EOF
done

Not 100% sure it'll work for ffmpeg thou, but works fine with read :)

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP