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 😢