MW

mp3dump take two - better audio quality

So just yesterday I’ve published a bash script which rips the audio stream of Flash Videos (*.flv) to mp3 format. It’s nice, fast and imo all-purpose. But I didn’t like the audio quality. Thus below you can find a second version of the script which is using mplayer and lame instead of ffmpeg. Usage and behaviour should be pretty much the same. Only the audio quality should be better on cost of a bit more computing.

Since it relies on the fact that the input *.flv video already uses MP3 encoding for its audio stream this might not work for every flash file! Youtube works just fine though. You can find the script after the break, it’s also attached below. For usage / installation / more information read the old article.

If you wonder why I reencode the audiodump with lame: The dumped mp3 file is considered by most (all?) audio players to be ~10x the length. A five minute video gets a 45 minute audio dumpfile. It plays fine but seeking is a mess. Reencoding fixes this. If you know an alternative which does not require reencoding or is generally faster - please drop a comment!

    #!/bin/bash
    #
    # Simple script to rip the audio stream of a FLV to MP3
    #
    # usage:    mp3dump INPUT.flv ARTIST TITLE
    # example:    mp3dump FlashhxSjv3 "Foo Bar" "All your Base are Belong to Us"
    # Author:    Milian Wolff
    # depends on:  mplayer, lame
    #   optional:  ecasound for stereo sound emulation
    #   optional:  mp3info to write title and artist mp3 tags
     
    if [[ "$(which mplayer)" == "" ]]; then
      echo -e "\033[41mThis script requires mplayer!\033[0m"
      exit
    fi
     
    if [[ "$(which lame)" == "" ]]; then
      echo -e "\033[41mThis script requires lame!\033[0m"
      exit
    fi
     
    if [[ "$1" == "" || "$2" == "" || "$3" == "" || "$4" != "" ]]; then
      echo "Usage: $(basename $0) INPUT.flv ARTIST TITLE"
      exit
    fi
     
    if [ ! -f "$1" ]; then
      echo "Input file \"$1\" could not be found!"
      exit
    fi
     
    if [[ "$(file -b "$1")" != "Macromedia Flash Video" ]]; then
      echo "Input file \"$1\" is not a valid flash video!"
      exit
    fi
     
    dest="$2 - $3.mp3"
    tmpfile="/tmp/$$-$dest"
     
    echo
    echo "Your mp3 output file will be: $dest"
    echo
    echo
     
    echo -n "dumping audio to mp3 file..."
    mplayer -nolirc -dumpaudio "$1" -dumpfile "$dest" 1>/dev/null
    echo -e " \033[32mdone\033[0m"
    echo
     
    echo -n "reencoding with lame - this might take some time..."
    lame --silent --preset standard --mp3input "$dest" "$tmpfile" && mv "$tmpfile" "$dest"
    echo -e " \033[32mdone\033[0m"
    echo
     
    if [[ "$(which ecasound)" == "" ]]; then
      echo "You can optionally install ecasound to simulate stereo sound"
      echo
    else
      echo -n "simulating stereo sound..."
     
      ecasound -d:1 -X -i "$dest" -etf:8 -o "$tmpfile" 1>/dev/null && mv "$tmpfile" "$dest"
     
      echo -e " \033[32mdone\033[0m"
      echo
    fi
     
     
    if [[ "$(which mp3info)" == "" ]]; then
      echo "You can optionally install mp3info to write basic mp3 tags automatically"
      echo
    else
      echo -n "writing basic mp3 tags..."
     
      mp3info -a "$2" -t "$3" "$dest"
     
      echo -e " \033[32mdone\033[0m"
      echo
    fi
     
    echo "Have fun with »$dest«"
Attachment Size
mp3dump.1.87 KB

Comments

Want to comment? Send me an email!

Comment by neversfelde (not verified) (2008-04-08 23:49:00)

Great script. I love it!

Published on April 08, 2008.