Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2013 00:05

Revisions

  1. @invalid-email-address Anonymous created this gist May 15, 2013.
    29 changes: 29 additions & 0 deletions convertToMp3.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/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