LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   combining ffmpeg commands for batch conversion (https://www.linuxquestions.org/questions/linux-software-2/combining-ffmpeg-commands-for-batch-conversion-4175576575/)

NathanSharp 04-03-2016 01:57 PM

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.

ntubski 04-03-2016 02:26 PM

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


ondoho 04-05-2016 02:30 AM

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.

NathanSharp 04-06-2016 11:28 AM

Quote:

Originally Posted by ntubski (Post 5525669)
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.


All times are GMT -5. The time now is 06:02 PM.