Monday, October 17, 2011

Linux - automate conversion of Youtube music to mp3

The following is a basic Linux bash script I use to convert music videos downloaded from Youtube into MP3 format. I have saved all my videos into category subfolders, so my line 7 actually reads for i in ./*/*.*; do

#!/bin/sh
FROMFOL=folder_full_of_flv_or_mp4_files
DESTFOL=folder_to_fill_with_mp3_files

cd $FROMFOL

for i in ./*.*; do
        TRIMMED=$(basename "${i}")
        if [ ! -f "${DESTFOL}${TRIMMED}".mp3 ];
        then
                ffmpeg -i "${i}" "${DESTFOL}${TRIMMED}".mp3
        fi
done

This script can then be added as a cron job to automate the conversion of new videos into MP3 files.

I use the firefox plug-in DownloadHelper to obtain youtube clips in the first place, which work well on the big screen at parties :)

0 comments:

Post a Comment