Posted: . At: 8:21 AM. This was 4 years ago. Post ID: 14718
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to download a Youtube video as an MP3 with Linux.


Saving a Youtube video as audio and not video is very easy. This command below will save Youtube audio as an MP3 file. You need youtube-dl as well. Then select a Youtube video and use this one-liner to download it as an MP3 audio file.

jason@jason-Lenovo-H50-55:~/Videos$ youtube-dl -f 140 https://www.youtube.com/watch?v=neEXAoYfcRo -o - | ffmpeg -hide_banner -i pipe: -strict -2 out.mp3
[youtube] neEXAoYfcRo: Downloading webpage
[download] Destination: -
[download]   2.6% of 580.15KiB at  5.03MiB/s ETA 00:00Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6mp41
    creation_time   : 2020-01-16T23:52:48.000000Z
  Duration: 00:00:36.66, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 34 kb/s (default)
    Metadata:
      creation_time   : 2020-01-16T23:52:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Output #0, mp3, to 'out.mp3':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6mp41
    TSSE            : Lavf58.29.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
    Metadata:
      creation_time   : 2020-01-16T23:52:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
      encoder         : Lavc58.54.100 libmp3lame
[download] 100% of 580.15KiB in 00:00
size=     574kB time=00:00:36.67 bitrate= 128.2kbits/s speed=39.6x
video:0kB audio:573kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.058920%

Use youtube-dl to view all available video and audio formats first.

jason@jason-Lenovo-H50-55:~/Videos$ youtube-dl -F https://www.youtube.com/watch?v=OLVLytIjf0s
[youtube] OLVLytIjf0s: Downloading webpage
[info] Available formats for OLVLytIjf0s:
format code  extension  resolution note
249          webm       audio only tiny   45k , opus @ 50k (48000Hz), 1.30MiB
250          webm       audio only tiny   57k , opus @ 70k (48000Hz), 1.63MiB
251          webm       audio only tiny  105k , opus @160k (48000Hz), 3.02MiB
140          m4a        audio only tiny  127k , m4a_dash container, mp4a.40.2@128k (44100Hz), 3.91MiB
278          webm       192x144    144p   84k , webm container, vp9, 25fps, video only, 2.26MiB
160          mp4        192x144    144p  111k , avc1.42c00c, 15fps, video only, 3.37MiB
242          webm       320x240    240p  184k , vp9, 25fps, video only, 5.19MiB
133          mp4        320x240    240p  246k , avc1.4d400d, 25fps, video only, 7.51MiB
243          webm       480x360    360p  357k , vp9, 25fps, video only, 9.45MiB
244          webm       640x480    480p  588k , vp9, 25fps, video only, 17.23MiB
134          mp4        480x360    360p  607k , avc1.4d4015, 25fps, video only, 17.87MiB
135          mp4        640x480    480p 1111k , avc1.4d401e, 25fps, video only, 33.30MiB
18           mp4        480x360    360p  726k , avc1.42001E, 25fps, mp4a.40.2@ 96k (44100Hz), 22.30MiB (best)

The number 140 format is the best.

This command will save audio as an Apple iPod m4a format file.

jason@jason-Lenovo-H50-55:~/Videos$ youtube-dl -f 140 https://www.youtube.com/watch?v=neEXAoYfcRo -o - | ffmpeg -hide_banner -i pipe: -strict -2 out.m4a
[youtube] neEXAoYfcRo: Downloading webpage
[download] Destination: -
[download]   2.6% of 580.15KiB at  4.87MiB/s ETA 00:00Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6mp41
    creation_time   : 2020-01-16T23:52:48.000000Z
  Duration: 00:00:36.66, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 34 kb/s (default)
    Metadata:
      creation_time   : 2020-01-16T23:52:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> aac (native))
Output #0, ipod, to 'out.m4a':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6mp41
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2020-01-16T23:52:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
      encoder         : Lavc58.54.100 aac
[download] 100% of 580.15KiB in 00:00
size=     559kB time=00:00:36.66 bitrate= 125.0kbits/s speed=57.2x
video:0kB audio:552kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.262669%
[aac @ 0x55eee2f52fc0] Qavg: 3214.323

But, this really does work very well. It is a great way to save music from Youtube as local files to listen to whenever you want.

This is another way to do it. This will also save the audio as an m4a file very easily.

jason@jason-Lenovo-H50-55:~/Videos$ ffmpeg -i $(youtube-dl -f 140 -g https://www.youtube.com/watch?v=laJpHzVtF9k) output.m4a

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.