Someone asked me if a YouTube clip can be saved locally (eg. as MP3 file). Being a Linux enthusiast I already knew that "on Linux one can do anything" so I gave it a try.
On Linux make sure you have the following programs installed:
If you only want to play a YouTube clip on your local system then just copy the YouTube link into clipboard and paste it as the parameter for the following command:
- mplayer $(youtube-dl -g <link>) where <link> is the YouTube link mentioned before
If you want to play the clip on a loop (eg. forever and ever) then make sure you add the "-loop 0" argument after mplayer command, i.e.: mplayer -loop 0 $(youtube-dl -g <link>)
If you want to dump the YouTube clip on the local disk then run the following command:
mplayer -dumpstream -dumpfile your-dump-file.asf $(youtube-dl -g <link>)
So you've got a local clip file called your-dump-file.asf that you can easily play whenever you want: mplayer your-dump-file.asf
I was asked to create a MP3 file format from it. So what we are going to do is to extract the audio part from the ASF clip and save it as a WAV file:
mplayerÂ your-dump-file.asf -novideo -vc dummy -ao "pcm:file=tmp.wav"
Now I have a .WAV file to play with. If you want to convert it to MP3 format then you can use (for example) the lame command:
lame tmp.wav my-mp3-file.mp3
Conclusion : in order to convert YouTube to MP3 format you need to follow these three simple steps:
- mplayer -dumpstream -dumpfile your-dump-file.asf $(youtube-dl -g <link>)
- mplayerÂ your-dump-file.asf -novideo -vc dummy -ao "pcm:file=tmp.wav"
- lame tmp.wav my-mp3-file.mp3
I was asked to convert a 27 seconds YouTube audio clip (Smiley - E ziua in care) to MP3:
mplayer -dumpstream -dumpfile smiley.asf $(youtube-dl -g https://www.youtube.com/watch?v=OazsPPL7CRU)
mplayer smiley.asf -novideo -vc dummy -ao "pcm:file=smiley.wav"
lame smiley.wav smiley.mp3
Here is the MP3 result. Enjoy it:
Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.
Latest posts by Eugen Mihailescu (see all)
- Dual monitor setup in Xfce - January 9, 2019
- Gentoo AMD Ryzen stabilizator - April 29, 2018
- Symfony Compile Error Failed opening required Proxies - January 22, 2018