Converting a youtube video to mp3 using ffmpeg WITHOUT youtube-dl

ffmpegyoutube

Is it possible to convert a youtube video to mp3 using ffmpeg but without youtube-dl to first put in on the server? All the examples I've seen involve youtube-dl first to extract the physical video file.

I don't have access to youtube-dl because I'm on shared web hosting so can't sudo.

Best Answer

Download video in a specific format from youtube

A browser and application-inspecific way is to use http://deturl.com/. Deturl.com owns both the http://deturl.com/ and http://pwnyoutube.com/ domains. To download a specific youtube video in any format, simply replace the youtube.com portion of the URL with either deturl.com or pwnyoutube.com (my personal fav).

For example, a movie with the URL www.youtube.com/watch?v=abcdefghijk would become www.pwnyoutube.com/watch?v=abcdefghijk. Follow the instructions on the download page to complete the conversion and download.

ALTERNATIVE

Out of interest, I checked on new alternatives and discovered ClipGrab. It, like Miro below, is an open-source and cross-platform application. Unlike Miro, however, it includes a built-in video downloader AND converter, one of which is the MP3 format. It doesn't include as many other conversion types as Miro, but you could always convert it with Miro after download if needed.

Convert a media file into another form/type (video->video, video->audio, or audio->audio)

Download the open-source and cross-platform Miro Video Converter (implements ffmpeg)

"Programmatic access"

To download/convert youtube videos from a command line (with ffmpeg integration), the aforementioned youtube-dl seems to be the best solution.

I'm not certain why sudo is needed to run youtube-dl. I switched over to linux and successfully completed various tasks without sudo or su -c. My output is below. Let us know where you hit a snag at. (echo's are just for comment purposes)

dono@Lonewolf stuff$ echo Download youtube-dl >> /dev/null
dono@Lonewolf stuff$ wget "http://youtube-dl.org/downloads/2013.06.33/youtube-dl"

--2013-06-25 16:37:07--  http://youtube-dl.org/downloads/2013.06.33/youtube-dl
Resolving youtube-dl.org (youtube-dl.org)... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177
Connecting to youtube-dl.org (youtube-dl.org)|95.143.172.170|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 117178 (114K) [application/octet-stream]
Saving to: ‘youtube-dl’

100%[======================================>] 117,178     91.3KB/s   in 1.3s

2013-06-25 16:37:10 (91.3 KB/s) - ‘youtube-dl’ saved [117178/117178]
dono@Lonewolf stuff$ echo Make executable >> /dev/null
dono@Lonewolf stuff$ chmod 764 youtube-dl
dono@Lonewolf stuff$ echo Download sample video >> /dev/null
dono@Lonewolf stuff$ ./youtube-dl http://www.youtube.com/watch?v=IYnsfV5N2n8
[youtube] Setting language
[youtube] IYnsfV5N2n8: Downloading video webpage
[youtube] IYnsfV5N2n8: Downloading video info webpage
[youtube] IYnsfV5N2n8: Extracting video information
[download] Destination: asdfmovie-IYnsfV5N2n8.flv
[download] 100.0% of 5.94MiB at 102.53KiB/s ETA 00:00
dono@Lonewolf stuff$ ls -sh | grep asdf
6.0M asdfmovie-IYnsfV5N2n8.flv
dono@Lonewolf stuff$ echo Download sample video as mp3 if ffmpeg exists >> /dev/null
dono@Lonewolf stuff$ ./youtube-dl -x --audio-format mp3 http://www.youtube.com/watch?v=IYnsfV5N2n8
[youtube] Setting language
[youtube] IYnsfV5N2n8: Downloading video webpage
[youtube] IYnsfV5N2n8: Downloading video info webpage
[youtube] IYnsfV5N2n8: Extracting video information
[download] Destination: asdfmovie-IYnsfV5N2n8.flv
[download] 100.0% of 5.94MiB at 40.83KiB/s ETA 00:00
[ffmpeg] Destination: asdfmovie-IYnsfV5N2n8.mp3
Deleting original file asdfmovie-IYnsfV5N2n8.flv (pass -k to keep)
dono@Lonewolf stuff$ ls -sh | grep asdf
6.0M asdfmovie-IYnsfV5N2n8.flv
1.1M asdfmovie-IYnsfV5N2n8.mp3
dono@Lonewolf stuff$ echo Resolve link for direct download >> /dev/null
dono@Lonewolf stuff$ ./youtube-dl -g http://www.youtube.com/watch?v=IYnsfV5N2n8
http://r12---sn-a5m7lm7z.c.youtube.com/videoplayback?fexp=905619%2C925301%2C914008%2C916612%2C901474%2C921047%2C928201%2C901208%2C929123%2C929915%2C929906%2C929907%2C929125%2C925714%2C929917%2C929919%2C931202%2C912512%2C912515%2C912521%2C906838%2C904488%2C906840%2C931910%2C931913%2C932227%2C904830%2C919373%2C933701%2C904122%2C900816%2C909421%2C912711%2C935000&nh=EAM&ipbits=8&algorithm=throttle-factor&burst=40&id=2189ec7d5e4dda7f&newshard=yes&mt=1372196857&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&cp=U0hWR1JNTl9NS0NONl9KR1JFOjR3WXdZbHR2LUVk&upn=LlOhvm7Kr9s&ip=97.195.135.218&sver=3&factor=1.25&mv=m&key=yt1&expire=1372220481&source=youtube&ms=au&itag=34&signature=4974B24AF7D8D3E239B55CDFDBD284A32734B180.D6A7029322940129A3F37F24BECE6DDE1DA08E61&ratebypass=yes

EDIT:

I think I see what went wrong. You were trying to wget a file to a /bin directory and it required su. If you create the directory ~/bin (e.g. /home/USERNAME/bin), it's still a searchable directory that you have full permissions to.

Assuming you were following the install directions listed at http://rg3.github.io/youtube-dl/download.html, run mkdir ~/bin and replace all instances of /usr/local/bin/youtube-dl with ~/bin/youtube-dl instead. I can verify that this works on my shared hosting provider (Arvixe).

Related Question