Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2013 00:05
Show Gist options
  • Save anonymous/5580728 to your computer and use it in GitHub Desktop.
Save anonymous/5580728 to your computer and use it in GitHub Desktop.
Bash script to convert a list of files to MP3 format.
#!/bin/bash
# Converts a list of files to mp3 format
# uses avconv, and requires ubuntu-restricted-extras package for the libmp3lame encoder.
# Example usage of this script:
# ./[scriptname] ./file_list.txt
# Notes on this script:
# - !!!IT DELETES THE INPUT FILE!!! (you can remove the line below in the do loop that rm's the input file)
# - Specifies max bitrate of 192k
# - Uses mp3 tags version id3v2.3, not the default 2.4 version. This makes it more compatible, especially
# with Windows.
# To create a list of files, use a command similar to this find command, which searches the current
# directory (.), for files that have a name ending in ".wma" (example for converting WMA to MP3):
# find . -type f | grep -e "\.wma$" > file_list.txt
# -- Begin Script -- #
file_list=$1
while read input_file;
do
output_file="$(echo $input_file | head -c -5).mp3"
avconv -y -i "$input_file" -maxrate 192k -acodec libmp3lame -id3v2_version 3 "$output_file"
rm "$input_file"
done < $file_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment