Extracting Audio From MP4 Videos
Iāve been asked to help someone create a device that can play steam train whistle sounds when a button is pressed. I was given a load of MP4 video files with recordings of the whistles.
FirstĀ I wanted to rename them because they all had a āPrj ā prefix on them. The code snippet below is what I used to remove the prefix from the file names.
for file in *.mp4 ; do mv "$file" $(echo "$file" | sed 's/Prj //') done
The next thing to do is extract the audio from all the videos. FFMPEG is perfect for this. The Bash code below will extract the audio fromĀ all of the MP4 files in a directory.
for file in *.mp4 ; do ffmpeg -i $file -map 0:1 -acodec pcm_s16le -ac 2 ${file/.mp4/.wav} done
Now that Iāve got the audio files I need to open them in Audacity and edit them, that is something I canāt automate unfortunatelyĀ š¢
automation bash ffmpeg programming tips