Monday, July 7, 2014

Convert all MP4 files to MP3 via avconv

IFS=$'\n' && for a in $(find . -maxdepth 1 -name "*.mp4" -type f -printf "%f\n" | rev | cut -d '.' -f2- | rev | sort -u); do if [ ! -f "$a.mp3" ]; then  avconv -i "$a."* -vn  -ab 128 "$a.mp3"; fi done && unset IFS
 

This may look a little strange but I wrote it originally to handle any type of file, it flips the filename around with rev and then cuts the first field off, this handles files with multiple "."'s such as

my.fav.music.mp4

and if you clip off the -name "*.mp4" it will try to convert every file in the directory to an mp3 if an mp3 doesn't already exist for it

No comments:

Post a Comment