virus.cmd
virus.cmd

Reputation: 344

Extract audio to stdout [youtube-dl]

I am trying to extract the audio from a video and output it to stdout. The closest I can get is to download the video to stdout.

youtube-dl -o - <link to video>

Does anyone know how to do this?

Regards, Austin

Upvotes: 3

Views: 5234

Answers (1)

Konstantin
Konstantin

Reputation: 3123

Try with option -f At first list the available formats with -F

youtube-dl -F  https://www.youtube.com/watch?v=CSKewNVWD0Y

Then look for the "audio only" formats:

249          webm       audio only DASH audio   62k , opus @ 50k, 20.17MiB
250          webm       audio only DASH audio   91k , opus @ 70k, 26.26MiB
171          webm       audio only DASH audio  128k , vorbis@128k, 44.89MiB
140          m4a        audio only DASH audio  132k , m4a_dash container, mp4a.40.2@128k, 51.17MiB
251          webm       audio only DASH audio  198k , opus @160k, 65.09MiB
278          webm       256x144    144p   46k , webm container, vp9, 6fps, video only, 11.36MiB
242          webm       426x240    240p   90k , vp9, 6fps, video only, 19.39MiB
160          mp4        256x144    144p  125k , avc1.4d400c, 6fps, video only, 15.18MiB
243          webm       640x360    360p  173k , vp9, 6fps, video only, 39.52MiB
134          mp4        640x360    360p  214k , avc1.4d4016, 6fps, video only, 47.51MiB
133          mp4        426x240    240p  255k , avc1.4d4015, 6fps, video only, 37.37MiB
17           3gp        176x144    small , mp4v.20.3,  mp4a.40.2@ 24k
36           3gp        320x180    small , mp4v.20.3,  mp4a.40.2
43           webm       640x360    medium , vp8.0,  vorbis@128k
18           mp4        640x360    medium , avc1.42001E,  mp4a.40.2@ 96k (best)

Format code 251 for opus @160 kbps. And finally you can use (optionally recode with ffmpeg):

youtube-dl -f 251 https://www.youtube.com/watch?v=CSKewNVWD0Y -o - | ffmpeg -i - -b:a 160k my_fav_novel.mp3

Upvotes: 7

Related Questions