Youtube video to mp3

· klm's blog


Original post is here: eklausmeier.goip.de

Assume you want to download just the music of below video on Youtube, so you can listen to the music on your phone, while you are on the road.

[youtube] aHjpOzsQ9YI [/youtube]

Here are the necessary steps on the command line:

1youtube-dl www.youtube.com/watch?v=aHjpOzsQ9YI
2mv Crystallize\ -\ Lindsey\ Stirling\ \(Dubstep\ Violin\ Original\ Song\)-aHjpOzsQ9YI.mp4 LindseyStirling-Crystallize.mp4
3avconv -i LindseyStirling-Crystallize.mp4 LindseyStirling-Crystallize.mp3

[more_WP_Tag]To cut only a portion of the video use the following command (ss is start time, t is duration):

1avconv -i file.mp4 -ss 00:02:23 -t 00:09:44 file.mp3

One can use ffmpeg instead of avconv. ffmpeg was initially written by this incredible French Fabrice Bellard, who is also the author of tcc.

avconv or ffmpeg on Ubuntu do not come with MP3 support by default. Sou you have to install this by

1apt-get install libavcodec-extra-53

Here are the relevant versions involved:

 1$ youtube-dl --version
 22013.12.17.2
 3
 4$ avconv -version
 5avconv version 0.8.10-4:0.8.10-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
 6  built on Feb  6 2014 20:56:59 with gcc 4.6.3
 7avconv 0.8.10-4:0.8.10-0ubuntu0.12.04.1
 8libavutil    51. 22. 2 / 51. 22. 2
 9libavcodec   53. 35. 0 / 53. 35. 0
10libavformat  53. 21. 1 / 53. 21. 1
11libavdevice  53.  2. 0 / 53.  2. 0
12libavfilter   2. 15. 0 /  2. 15. 0
13libswscale    2.  1. 0 /  2.  1. 0
14libpostproc  52.  0. 0 / 52.  0. 0

See also: superuser: How can I convert MP4 video to MP3 audio with ffmpeg?

For moving the MP3 file to my Android phone I use SSHelper, see also ssh and rsync for Android.