Code Snippetsmp3dump: Rip the audio stream of a Flash video to MP3 Syndicate content

Fri, 03/28/2008 - 00:03

UPDATE: Also check out mp3dump part 2

On some undefined occasion you might want to dump the audio stream of a flash file. This is how you do it:

  1. Get the *.flv, e.g. visit youtube with Konqueror and check /tmp for a file like FlashV5SQLt - this is your FLV.
  2. Install some dependencies: ffmpeg is required, mp3info and ecasound are optional but strongly recommended.
  3. Download the script below (it’s attached!) and save it inside your $PATH, remember how you’ve called it!
  4. I’ve saved the script inside ~/.bin which is inside my $PATH so all I have to do now is running it:

    mp3dump FlashV5SQLt "Foo Bar" "All Your Base Are Belong To Us"

    This would rip the audio stream of FlashV5SQLt to a file named Foo Bar - All Your Base Are Belong To Us.mp3 - with emulated stereo sound and basic MP3 tags (artist and title). Coolio!

So what does this neat-o-bash-magic look like?

Note: The script is attached below, so no copy’n’paste is required (but optionally supported :-) )

  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: ffmpeg
  9. # optional: ecasound for stereo sound emulation
  10. # optional: mp3info to write title and artist mp3 tags
  12. if [[ "$(which ffmpeg)" == "" ]]; then
  13. echo -e "\033[41mInstall ffmpeg or this script wont work!\033[0m"
  14. exit
  15. fi
  17. if [[ "$1" == "" || "$2" == "" || "$3" == "" || "$4" != "" ]]; then
  18. echo "Usage: $(basename $0) INPUT.flv ARTIST TITLE"
  19. exit
  20. fi
  22. dest="$2 - $3.mp3"
  23. tmpfile="/tmp/$$-$dest"
  25. echo "Destination file is: $dest"
  26. echo
  27. echo
  29. echo "generating mp3 file..."
  30. echo
  31. ffmpeg -i "$1" -f mp3 -vn -acodec copy "$dest" 1>/dev/null
  32. echo
  33. echo -e " \033[32mdone\033[0m"
  34. echo
  36. if [[ "$(which ecasound)" == "" ]]; then
  37. echo "You can optionally install ecasound to simulate stereo sound"
  38. echo
  39. else
  40. echo -n "simulating stereo sound..."
  42. ecasound -d:1 -X -i "$dest" -etf:8 -o "$tmpfile" 1>/dev/null
  43. mv "$tmpfile" "$dest"
  45. echo -e " \033[32mdone\033[0m"
  46. echo
  47. fi
  50. if [[ "$(which mp3info)" == "" ]]; then
  51. echo "You can optionally install mp3info to write basic mp3 tags automatically"
  52. echo
  53. else
  54. echo -n "writing basic mp3 tags..."
  56. mp3info -a "$2" -t "$3" "$dest"
  58. echo -e " \033[32mdone\033[0m"
  59. echo
  60. fi
  62. echo "Have fun with »$dest«"

PS: I totally forgot to mention that I got the basic ffmpeg & ecasound commands from this thread by SuperMike:

mp3dump.1.35 KB


I always did it manually with Mon, 06/29/2009 - 22:44 — Alan (not verified)

I always did it manually with mplayer -dumpaudio and then tagged it with eye3d. The tip about stereo sound is priceless. Thanks.

thanks, was looking for some Sun, 11/23/2008 - 21:50 — Jan (not verified)

thanks, was looking for some code for a new project. youtube does not use flv by any chance, does it?

Actually, it does: As I Wed, 11/26/2008 - 18:45 — Milian Wolff

Actually, it does:

As I mentioned at the beginning of the article, you can simply visit Youtube with your favorite browser under Linux and you’ll find the video you are watching somewhere under /tmp (look for cryptic names like FlashMYeMdJ). Make sure to rip before you close the page in your browser, else the temporary file will be deleted.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • 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