LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-03-2016, 02:57 PM   #1
NathanSharp
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Rep: Reputation: Disabled
combining ffmpeg commands for batch conversion


Quote:
find . -iname "*.m4a" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME/.m4a/.mp3}" && rm "$NAME"' \;

find . -iname "*.opus" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME/.opus/.mp3}" && rm "$NAME"' \;

find . -iname "*.webm" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME/.webm/.mp3}" && rm "$NAME"' \;

find . -iname "*.ogg" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME/.ogg/.mp3}" && rm "$NAME"' \;
All of these commands batch convert different formats to mp3 and erase the original files. Is there a way I can combine all of them as one command that runs in sequence? At the moment I have to run all of them separately.
 
Old 04-03-2016, 03:26 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,549

Rep: Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842
Something like

Code:
find . -iregex '.*\.\(m4a\|opus\|webm\|ogg\)$' -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME%.*}.mp3" && rm "$NAME"' \;
With a recent (4+) bash, you could also try
Code:
shopt -s globstar extglob nullglob
for NAME in **.@(m4a|opus|webm|ogg) ; do
    ffmpeg -y -i "$NAME" -ab 360k "${NAME%.*}.mp3" && rm "$NAME"
done
 
1 members found this post helpful.
Old 04-05-2016, 03:30 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,413
Blog Entries: 9

Rep: Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658Reputation: 3658
i'm not sure what you are trying to achieve (regular, automated conversions? one shot?) but i think you should write yourself a proper shell script for this, instead of angling for a one-liner (why?).

also, the && assumes that the previous find command returns true, keep that in mind.
 
1 members found this post helpful.
Old 04-06-2016, 12:28 PM   #4
NathanSharp
LQ Newbie
 
Registered: Apr 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Something like

Code:
find . -iregex '.*\.\(m4a\|opus\|webm\|ogg\)$' -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 360k "${NAME%.*}.mp3" && rm "$NAME"' \;
With a recent (4+) bash, you could also try
Code:
shopt -s globstar extglob nullglob
for NAME in **.@(m4a|opus|webm|ogg) ; do
    ffmpeg -y -i "$NAME" -ab 360k "${NAME%.*}.mp3" && rm "$NAME"
done
Thanks, this works great.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
batch syntax for 'ffmpeg -i'? newbiesforever Linux - Software 2 05-05-2013 10:56 AM
dvd batch conversion layer1man Linux - Software 1 10-25-2005 09:06 AM
audacity, batch conversion mifan Linux - Software 1 08-19-2005 03:51 AM
Character conversion combining cat and pipe lda_ga Linux - General 5 08-04-2005 03:45 PM
Batch image conversion mrsolo Linux - Software 1 09-06-2004 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:28 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration