0

I want to make a "batch" file so to say for some bash commands (convert.sh). I think it would be best to describe the situation. i have a $#!^ ton of mp4 videos that i want converted into mp3's. it would take me an unreasonable amount of time to convert them using ffmpeg -i /root/name\ of\ video.mp4 /name\ of\ video.mp3 for every single video. not to mention the fact that all the file names are long and complicated so typos are a possibility. so i want to know how to make a shell script (for bash) that will take every file with the extension .mp4 and convert it to a .mp3 with the same name one by one. as in it converts one then when it done it moves on to the next one. im using a lightweight version of linux so any 3rd part soft probably wont work so i need to use ffmpeg...

many thanks in advance for any assistance you can provide

PS: i cant seem to get the formatting sytax on the website to work right so if somone can format this for me and maybe post a link to a manual on how it works that would be much appreciated =)

PPS: i understand that questions about using the ffmpeg command should be asked on superuser however since i dont so much have any questions about the specific command and this relates more to scripting a bash file i figure this is the right place

2 Answers2

1

A bash for loop should do it for you in no time:

SRC_DIR=/root
DST_DIR=/somewhereelse
for FILE in ${SRC_DIR}/*.mp4
do
    ffmpeg -i "${FILE}" "${DST_DIR}/$(basename \"${FILE}\" .mp4).mp3"
done

Sorry - I don't know the ffmpeg command line options, so I just copied exactly what's in your post.

Carl Norum
  • 210,715
  • 34
  • 410
  • 462
0

1) use find:

find . -name \*.mp4 | xargs ./my_recode_script.sh

2) my_recode_script.sh - see this question so you can easily change the extension for output file name

the rest is trivial scripting job:

ffmpeg -i $name $new_name # in my_recode_script.sh after changing extension

this is enough for one-time script, if you want something reusable, wrap it with yet another script which receive path to dir, extensions from which to which to recode and call other parts :)

Community
  • 1
  • 1
VB9-UANIC
  • 310
  • 1
  • 5