Code Snippetsmp3dump take two - better audio quality Syndicate content

Sat, 03/29/2008 - 16:29

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!

  1. #!/bin/bash
  2. #
  3. # Simple script to rip the audio stream of a FLV to MP3
  4. #
  5. # usage: mp3dump INPUT.flv ARTIST TITLE
  6. # example: mp3dump FlashhxSjv3 "Foo Bar" "All your Base are Belong to Us"
  7. # Author: Milian Wolff
  8. # depends on: mplayer, lame
  9. # optional: ecasound for stereo sound emulation
  10. # optional: mp3info to write title and artist mp3 tags
  11.  
  12. if [[ "$(which mplayer)" == "" ]]; then
  13. echo -e "\033[41mThis script requires mplayer!\033[0m"
  14. exit
  15. fi
  16.  
  17. if [[ "$(which lame)" == "" ]]; then
  18. echo -e "\033[41mThis script requires lame!\033[0m"
  19. exit
  20. fi
  21.  
  22. if [[ "$1" == "" || "$2" == "" || "$3" == "" || "$4" != "" ]]; then
  23. echo "Usage: $(basename $0) INPUT.flv ARTIST TITLE"
  24. exit
  25. fi
  26.  
  27. if [ ! -f "$1" ]; then
  28. echo "Input file \"$1\" could not be found!"
  29. exit
  30. fi
  31.  
  32. if [[ "$(file -b "$1")" != "Macromedia Flash Video" ]]; then
  33. echo "Input file \"$1\" is not a valid flash video!"
  34. exit
  35. fi
  36.  
  37. dest="$2 - $3.mp3"
  38. tmpfile="/tmp/$$-$dest"
  39.  
  40. echo
  41. echo "Your mp3 output file will be: $dest"
  42. echo
  43. echo
  44.  
  45. echo -n "dumping audio to mp3 file..."
  46. mplayer -nolirc -dumpaudio "$1" -dumpfile "$dest" 1>/dev/null
  47. echo -e " \033[32mdone\033[0m"
  48. echo
  49.  
  50. echo -n "reencoding with lame - this might take some time..."
  51. lame --silent --preset standard --mp3input "$dest" "$tmpfile" && mv "$tmpfile" "$dest"
  52. echo -e " \033[32mdone\033[0m"
  53. echo
  54.  
  55. if [[ "$(which ecasound)" == "" ]]; then
  56. echo "You can optionally install ecasound to simulate stereo sound"
  57. echo
  58. else
  59. echo -n "simulating stereo sound..."
  60.  
  61. ecasound -d:1 -X -i "$dest" -etf:8 -o "$tmpfile" 1>/dev/null && mv "$tmpfile" "$dest"
  62.  
  63. echo -e " \033[32mdone\033[0m"
  64. echo
  65. fi
  66.  
  67.  
  68. if [[ "$(which mp3info)" == "" ]]; then
  69. echo "You can optionally install mp3info to write basic mp3 tags automatically"
  70. echo
  71. else
  72. echo -n "writing basic mp3 tags..."
  73.  
  74. mp3info -a "$2" -t "$3" "$dest"
  75.  
  76. echo -e " \033[32mdone\033[0m"
  77. echo
  78. fi
  79.  
  80. echo "Have fun with »$dest«"
AttachmentSize
mp3dump.1.87 KB

Comments

Great script. I love it! Tue, 04/08/2008 - 23:49 — neversfelde (not verified)

Great script. I love it!

Post new comment

  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options