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Ā šŸ˜¢

         

Contolling the CPU Governor in Linux

Recently I wondered how you control CPUĀ throttlingĀ in GNU/Linux systems so after doing a little research this script is what Iā€™ve come up with. Itā€™s based on some others that Iā€™ve comeĀ across. All it does is set the CPU throttling mode to ā€œperformanceā€ then displays the current CPU frequency setting, which should be full speed.

#!/bin/sh
for CPUGOV in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
do
    echo -n performance > $CPUGOV;
done
 
# Display Stats about new settings
grep -E '^model name' /proc/cpuinfo | head -n 1
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
do
    cat  $CPUFREQ | awk '{ print $1 / 1e6 "GHz"; }'
done
 
exit 0