Here’s a nifty little script that will take a YouTube URL as an argument, pull down the associated flv and convert it into mp3 format. It’s basically all shell but I wrapped it with php.
First:
Take the YouTube URL as an argument
$url = $argv[1];
Next:
Use a little shell magic to grab the video arguments for later use:
$vid_args = `lynx -source "$url" | grep video_id | grep fullscreen | awk -F'video_id=' '{print $2}' | awk -F'&title'
Next:
use basically the same command to grab the title of the video:
$title = 'lynx -source "$url" | grep video_id | grep fullscreen | awk -F'video_id=' '{print $2}' | awk -F'&title=' '{print $2}' ';
Then:
Do a little formatting of the title to make it useable:
$title = preg_replace("| |", "_", $title);
$title = trim($title);
$title = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $title);
$title = preg_replace("|'|", "", $title);
$title = preg_replace("|\)|", "", $title);
$title = preg_replace("|\(|", "", $title);
$title = preg_replace("|\/|", "_", $title);
Then:
Grab the flv with the video arguments you captured from the line above:
'wget -O /tmp/$title.flv "http://www.youtube.com/get_video?video_id=$vid_args"';
Next:
Use ffmpeg to break it down to mp3 format:
'ffmpeg -i /tmp/$title.flv -ar 44100 -ab 160k -ac 2 /tmp/$title.mp3';
Finally:
Dump the flv and enjoy:
'rm -f /tmp/$title.flv';
These files are of course only for educational purposes when you are finished so make sure you delete them
9 Responses to Strip MP3s from YouTube with ffmpeg.
Chantelle
June 13th, 2011 at 5:23 am
hello…
really good article. Ready to hear more next week,my blog http://blogtext.org/talonmpgraham/article/548324.html Many Thanks….
Richelle
June 13th, 2011 at 7:26 pm
hello…
really good article. Ready to hear more next week,my blog http://eveningdressesvuv.sweetcircles.com/2010/12/20/low-priced-night-dresses/ Many Thanks….
Kenzing
June 20th, 2011 at 6:29 am
hello…
Hello there thanks for the quality post! http://mamies11.blogth.com/ ,i’d a great read.appreciate your article,My problem has been resolved….
Ehantelle
June 20th, 2011 at 7:34 pm
very helpful…
I preferred to thank you for this good article. http://bbzgmy.fotopages.com/ I by all odds liked every little bit of it…
sander
June 21st, 2011 at 5:00 pm
Great…
You did a great job! http://denita.quebecblogue.com/2011/06/20/rachel-gilbert-night-creatures/…
TadWinett
June 22nd, 2011 at 8:10 am
Great…
You did a great job! http://dennise.sunteu.ro/2011/06/20/kookai-basics-with-detail/…
Sterker
June 27th, 2011 at 11:48 pm
Greate…
It’s such a great site! http://ashantihwhoudgxt.gather.com Great post, I just bookmarked it on Digg….
Kugenie
July 18th, 2011 at 6:52 pm
Great One…
I must say, its worth it! My link!http://duffy071.mylivepage.com/blog/2138/2466 ,thanks haha…
Khantelle
December 2nd, 2011 at 2:45 am
quality post…
fluffy ugg boots love, http://www.elmodenawrestling.com ,thanks ugg…