Convert all videos into directory to audio only

Posted on Fri 08 May 2020 in dev-journal

Here is a script I wrote today to convert all .mp4 videos in a folder to audio so I can listen to them while I drive.

!#/bin/bash
find -name '*.mp4' | while read file
do
    filename=$(basename -- "$file")

    # get the file extension - this line could be useful in other cases
    extension="${filename##*.}"
    # get the filename without the current extension
    filename="${filename%.*}"
    p="../mp3/$filename"

    # have to use the < /dev/null so that ffmpeg doesn't try to read its
    # own standard input
    # see http://mywiki.wooledge.org/BashFAQ/089
    ffmpeg -i "$file" -threads 0 -q:a 0 -map a "$p.mp3" < /dev/null &
done