Use VLC to extract original sound file from youtube video

How to do things, solutions, recipes, tutorials
Message
Author
User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

Use VLC to extract original sound file from youtube video

#1 Post by nic007 »

This method is to preserve and download the original sound track of a youtube video, only, without having to convert to another format or bitrate (and lose audio quality). Almost all youtube videos' sound tracks are encoded with the vorbis (ogg) encoder.

Method: Open VLC player > select Media from menu > select Convert/Save > click Network > enter the video url > select Convert at the bottom > In Settings select Convert (should be the default) and for profile select Audio/Vorbis (OGG) > click the edit selected profile button and select the Audio codec tab > tick audio AND tick Keep original audio track > save the settings > enter your destination file and click Start. You do not have to download the video first but if you have already done so, the same method can be followed to extract the original sound file of the video (just add the file path instead of an url).

april

#2 Post by april »

I'm wondering why you would want to do that? To collect music maybe? Don't see it so why separate the audio? Maybe to adjust the timing on a video

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#3 Post by mcewanw »

april wrote:I'm wondering why you would want to do that? To collect music maybe? Don't see it so why separate the audio? Maybe to adjust the timing on a video
I think, both these reasons you mention are good ones.

In particular, though, despite the move away from simple mp3 players to smartphones, which can play video too, as drivers, we only currently need audio in our car-players (until such time as we all inhabit driverless cars...). Audio takes up much less storage space than video of course. The Times and thus the needs are neverless A'Changing - one day, in the nearish future of huge storage availability and enormous personal computer-power, we might all want and expect 3D... audio and video.

William
github mcewanw

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#4 Post by nic007 »

april wrote:I'm wondering why you would want to do that? To collect music maybe? Don't see it so why separate the audio? Maybe to adjust the timing on a video
To download the original youtube soundtrack without any further loss of audio quality and to limit the size of the download. I sometimes want to download some of these album compilations. In many cases these videos consist of a single picture displayed throughout the video (which basically contains only a soundtrack). The audio part of the video may be 100 mb for example whilst the size of the video itself will be much larger, sometimes even double or more the size of the actual soundtrack (even if it contains only one still picture).

april

#5 Post by april »

Nah Modern day video compresses very efficiently any video file that contains a series of pictures that remain the same for some seconds so I don't see any point in what you are doing yet.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#6 Post by nic007 »

april wrote:Nah Modern day video compresses very efficiently any video file that contains a series of pictures that remain the same for some seconds so I don't see any point in what you are doing yet.
Then those "modern video compressors" are most definitely NOT used by youtube. Why don't you download a youtube video and extract the audio part to see for yourself (instead of talking bullshit). Oh wait, its you...carry on.

april

#7 Post by april »

nic007 wrote:
april wrote:Nah Modern day video compresses very efficiently any video file that contains a series of pictures that remain the same for some seconds so I don't see any point in what you are doing yet.
Then those "modern video compressors" are most definitely NOT used by youtube. Why don't you download a youtube video and extract the audio part to see for yourself (instead of talking bullshit). Oh wait, its you...carry on.
Still as rude as ever I see and just as neurotic
I left the door open too , I said "yet" , got any more crap?

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#8 Post by nic007 »

april wrote:
nic007 wrote:
april wrote:Nah Modern day video compresses very efficiently any video file that contains a series of pictures that remain the same for some seconds so I don't see any point in what you are doing yet.
Then those "modern video compressors" are most definitely NOT used by youtube. Why don't you download a youtube video and extract the audio part to see for yourself (instead of talking bullshit). Oh wait, its you...carry on.
Still as rude as ever I see and just as neurotic
I left the door open too , I said "yet" , got any more crap?
Nah, you are just looking for a shitfight. Cheers

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#9 Post by phat7 »


User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#10 Post by nic007 »

That is exactly what we want to avoid ie. converting the audio again. With the method described above, the original audio track of the video is downloaded without any further conversion (encoding).

april

#11 Post by april »

Code: Select all

ffmpeg -i video.mp4 -ab 192 out_sound.mp3 
"video.mp4" is the name of your video
"out_sound.mp3" is the name of the file that comes out
"-ab 192" I'll have to look up

Works a treat thanks
According to the data in ffmpeg that program has been superceded by avconv and you will find

Code: Select all

avconv -i video.mp4 -ab 192 out_sound.mp3 
will give the same result.Its extracted at 128 kbits/sec

Wouldn't credit it but I came across a Russian festival video with slides and fades between that had a 27Meg overall size . I liked the music behind it so decided to try and get it . Used the above after d/l the file as mp4 and got an audio file of 6Meg so there is some to be saved . I wonder though if the fades between slides were not there what size it would be . I'd test it but its too much work.

https://www.youtube.com/watch?v=cYvyjdli8rQ

Code: Select all

# ffmpeg -i video.mp4 -ab 192 out_sound.mp3 
ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:00:59 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-09 07:46:44
  Duration: 00:06:18.13, start: 0.000000, bitrate: 590 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 492 kb/s, 29.87 fps, 30 tbr, 30 tbn, 60 tbc
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
Output #0, mp3, to 'out_sound.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TDEN            : 2016-08-09 07:46:44
    TSSE            : Lavf53.21.1
    Stream #0.0(eng): Audio: libmp3lame, 44100 Hz, stereo, s16, 0 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
Stream mapping:
  Stream #0.1 -> #0.0
Press ctrl-c to stop encoding
size=    5909kB time=378.17 bitrate= 128.0kbits/s    
video:0kB audio:5909kB global headers:0kB muxing overhead 0.004313%
# avconv -i video.mp4 -ab 192 out_sound.mp3 
avconv version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:00:59 with gcc 4.6.3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-09 07:46:44
  Duration: 00:06:18.13, start: 0.000000, bitrate: 590 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 492 kb/s, 29.87 fps, 30 tbr, 30 tbn, 60 tbc
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
File 'out_sound.mp3' already exists. Overwrite ? [y/N] y
The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
Output #0, mp3, to 'out_sound.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TDEN            : 2016-08-09 07:46:44
    TSSE            : Lavf53.21.1
    Stream #0.0(eng): Audio: libmp3lame, 44100 Hz, stereo, s16, 0 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libmp3lame)
Press ctrl-c to stop encoding
size=    5909kB time=378.17 bitrate= 128.0kbits/s    
video:0kB audio:5909kB global headers:0kB muxing overhead 0.004313%
# 
# ffmpeg -i video.mp4 -ab 192 out_sound.mp3 
ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:00:59 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-09 07:46:44
  Duration: 00:06:18.13, start: 0.000000, bitrate: 590 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 492 kb/s, 29.87 fps, 30 tbr, 30 tbn, 60 tbc
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
Output #0, mp3, to 'out_sound.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TDEN            : 2016-08-09 07:46:44
    TSSE            : Lavf53.21.1
    Stream #0.0(eng): Audio: libmp3lame, 44100 Hz, stereo, s16, 0 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
Stream mapping:
  Stream #0.1 -> #0.0
Press ctrl-c to stop encoding
size=    5909kB time=378.17 bitrate= 128.0kbits/s    
video:0kB audio:5909kB global headers:0kB muxing overhead 0.004313%
# avconv -i video.mp4 -ab 192 out_sound.mp3 
avconv version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:00:59 with gcc 4.6.3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-09 07:46:44
  Duration: 00:06:18.13, start: 0.000000, bitrate: 590 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 492 kb/s, 29.87 fps, 30 tbr, 30 tbn, 60 tbc
    Stream #0.1(eng): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
File 'out_sound.mp3' already exists. Overwrite ? [y/N] y
The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
Output #0, mp3, to 'out_sound.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TDEN            : 2016-08-09 07:46:44
    TSSE            : Lavf53.21.1
    Stream #0.0(eng): Audio: libmp3lame, 44100 Hz, stereo, s16, 0 kb/s
    Metadata:
      creation_time   : 2016-08-09 07:46:46
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libmp3lame)
Press ctrl-c to stop encoding
size=    5909kB time=378.17 bitrate= 128.0kbits/s    
video:0kB audio:5909kB global headers:0kB muxing overhead 0.004313%
# 

Last edited by april on Wed 10 Aug 2016, 11:32, edited 1 time in total.

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#12 Post by Pete »

The ffmpeg (amongst other) methods work to extract the audio, but what nic007 is rightly saying is, it re-encodes the audio to another format and hence you will get degradation.

It may be that the original audio was encoded with enough quality to "survive" yet another encoding with no perceptible deterioration but strictly it is still degrading.
It all depends on what one is playing the resulting audio with.
If it's a smartphone or portable mp3/media player with crappy earphones, I doubt it would make a difference but play it into a good setup with proper full range speakers and the difference is audible.
Not only in frequency response, but dynamic range, inter-modulation and THD as well.

Even if one knows nothing about these terms, the difference is immediately audible to most people when played side by side.

So, if one already has the mp4 and the audio needs to be extracted, the best is still good old PCM (a.k.a. wav) or use a lossless codec like flac, assuming of course that the player can handle those formats.
Also keep in mind that if the original audio in the mp4 is rubbish, converting to pcm or flac is certainly not going to improve it.
It will simply be a case of garbage in, garbage out.

So in the end it comes down to one thing, does it sound good enough?
Everyone is different and if the answer for you is yes, then great, continue.

april

#13 Post by april »

Ha Ha thats great explains it well

I got clobbered and destroyed my inner ear bones when I was 5 and only ever remember sound in mono. it makes little difference to me

I guess though with a little crafting, the command could be made to give whatever you want .Flac is one option I have definitely seen in the GUI

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#14 Post by Pete »

@april

Sorry to hear about your ear and I hope you are looking after the other one.
Watch those SPL's (Sound Pressure Levels) as modern earphones can give out very high levels which will cause hearing damage over time.

By default, we tend to lose (on average) about 1Khz/10 years of age off the top end (treble frequencies) and sustained exposure to high sound levels will accelerate this.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#15 Post by nic007 »

Pete wrote:The ffmpeg (amongst other) methods work to extract the audio, but what nic007 is rightly saying is, it re-encodes the audio to another format and hence you will get degradation.

It may be that the original audio was encoded with enough quality to "survive" yet another encoding with no perceptible deterioration but strictly it is still degrading.
It all depends on what one is playing the resulting audio with.
If it's a smartphone or portable mp3/media player with crappy earphones, I doubt it would make a difference but play it into a good setup with proper full range speakers and the difference is audible.
Not only in frequency response, but dynamic range, inter-modulation and THD as well.

Even if one knows nothing about these terms, the difference is immediately audible to most people when played side by side.

So, if one already has the mp4 and the audio needs to be extracted, the best is still good old PCM (a.k.a. wav) or use a lossless codec like flac, assuming of course that the player can handle those formats.
Also keep in mind that if the original audio in the mp4 is rubbish, converting to pcm or flac is certainly not going to improve it.
It will simply be a case of garbage in, garbage out.

So in the end it comes down to one thing, does it sound good enough?
Everyone is different and if the answer for you is yes, then great, continue.
Not quite. The audio track in the youtube video is already in a compressed state ie. either ogg vorbis or mp4a. VLC makes it possible to extract the soundtrack exactly as it is. For example: if the soundtrack is 128kb/s in ogg vorbis format, that file will be extracted exactly like that (a 128kb/s .ogg file) without any loss in audio quality. Listening to this file in this format is the best you can do. You can extract to wave from the ogg format whithout further loss of sound quality but then you will sit with a massive file. You can't improve the sound quality of the extracted ogg or mp4a file.

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#16 Post by Pete »

@nic007

Exactly.
I always convert to wav at 48KHz sample rate and use 24 bit audio pcm_sle24,
the reason being that it gives me more dynamic range that way should I need to apply filters, dynamic compression or conversions.
For me file size is not an issue, quality is, hence the pcm 48KHz 24 bit format

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#17 Post by nic007 »

Pete wrote:@nic007

Exactly.
I always convert to wav at 48KHz sample rate and use 24 bit audio pcm_sle24,
the reason being that it gives me more dynamic range that way should I need to apply filters, dynamic compression or conversions.
For me file size is not an issue, quality is, hence the pcm 48KHz 24 bit format
Just as long as we understand that converting to wave at whatever sample rate from the original compressed file will not increase the audio quality of the file of origin. I take your point that converting to wave may give you more options to do whatever you want to do with the sound furtheron (applying effects, etc. to make it sound better for the human ear). The same way we use equalizers, etc to make it sound "better"). The raw material is still the same though. I use XMPlay to play my music. It uses the very excellent old winamp DSP plugins.

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#18 Post by Pete »

@nic007
Just as long as we understand that converting to wave at whatever sample rate from the original compressed file will not increase the audio quality of the file of origin.
Absolutely, as I said a few posts back:
Also keep in mind that if the original audio in the mp4 is rubbish, converting to pcm or flac is certainly not going to improve it.
It will simply be a case of garbage in, garbage out.
Although you would be surprised at what Protools with the Isotope plug-in can do with crappy quality.
Certainly not a substitute but at times one has no option. :wink:

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#19 Post by mcewanw »

What is interesting about nic007's suggestion of using VLC to extract the audio will be if it indeed does so without having to first download the video. I haven't tried his method because I don't have VLC on my system currently.

If you have already downloaded a video, you can of course use ffmpeg to extract the audio track without re-encoding the audio at all. To do so, you use the -c:a copy encoder, which simply tells ffmpeg to copy out the audio track exactly as it is already stored:

For example, you can copy the original audiotrack from videoname (include its extension) into an m4a container:

ffmpeg -i videoname -vn -c:a copy audiotrack.m4a

The -vn option means to not include the video track.

I use this ffmpeg method often, and usually the size of the resulting audio file is considerably less than the original video, as nic007 says.

I do occasionally re-encode to say mp3 (similar to the earlier quoted ffmpeg command) if the player I want to use doesn't understand the original format, but of course the sound quality is going to be degraded then.

The VLC method sounds very good to me since anything to reduce download size is a bonus IMO. However, I would be interested to know how VLC is able to 'tell' youtube not to 'send' the original video but just the audio track. Does youtube have a special webpage URL that points to only the audio track? I certainly didn't know that.

William
github mcewanw

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#20 Post by Pete »

Youtube automatically makes and keeps not only multiple copies of the video, but it also strips the audio and keeps a copy.
This is done once a user uploads their video.

The browser (or in this case VLC) fetches what is required by means of flags in the URL.

The reason Youtube keeps multiple copies is so that it can serve you one that best matches your connection speed.
Netflix does a similar thing.

I don't know all the flags, but some are:

vq=large for 480p
vq=hd720 for 720p
vq=hd1080 for 1080p
2K and 4K also supported but don't know their flags.

These are the new ones, the old way of specifying (which may still work):

&fmt=35, &fmt=22, or &fmt=37

Post Reply