terminalyoutubeyoutube-dlyt-dlp

How to download multiple formats using youtube-dl


$ youtube-dl -F --no-playlist https://youtu.be/LsdxvjLWkIY?list=PLeo1K3hjS3uu7CxAacxVndI4bE_o3BDtO

[youtube:tab] Downloading just video LsdxvjLWkIY because of --no-playlist
[youtube] LsdxvjLWkIY: Downloading webpage
[youtube] Downloading just video LsdxvjLWkIY because of --no-playlist
[info] Available formats for LsdxvjLWkIY:
format code  extension  resolution note
249          webm       audio only tiny   45k , webm_dash container, opus @ 45k (48000Hz), 8.37MiB
250          webm       audio only tiny   57k , webm_dash container, opus @ 57k (48000Hz), 10.68MiB
251          webm       audio only tiny  100k , webm_dash container, opus @100k (48000Hz), 18.68MiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 23.99MiB
160          mp4        256x144    144p   33k , mp4_dash container, avc1.4d400c@  33k, 30fps, video only, 6.27MiB
278          webm       256x144    144p   35k , webm_dash container, vp9@  35k, 30fps, video only, 6.66MiB
242          webm       426x240    240p   53k , webm_dash container, vp9@  53k, 30fps, video only, 9.95MiB
133          mp4        426x240    240p   69k , mp4_dash container, avc1.4d4015@  69k, 30fps, video only, 12.94MiB
243          webm       640x360    360p   93k , webm_dash container, vp9@  93k, 30fps, video only, 17.25MiB
134          mp4        640x360    360p  127k , mp4_dash container, avc1.4d401e@ 127k, 30fps, video only, 23.58MiB
244          webm       854x480    480p  144k , webm_dash container, vp9@ 144k, 30fps, video only, 26.72MiB
135          mp4        854x480    480p  210k , mp4_dash container, avc1.4d401f@ 210k, 30fps, video only, 38.92MiB
247          webm       1280x720   720p  269k , webm_dash container, vp9@ 269k, 30fps, video only, 49.86MiB
136          mp4        1280x720   720p  368k , mp4_dash container, avc1.64001f@ 368k, 30fps, video only, 68.31MiB
248          webm       1920x1080  1080p  365k , webm_dash container, vp9@ 365k, 30fps, video only, 67.79MiB
137          mp4        1920x1080  1080p  625k , mp4_dash container, avc1.640028@ 625k, 30fps, video only, 115.91MiB
271          webm       2560x1440  1440p 1029k , webm_dash container, vp9@1029k, 30fps, video only, 190.72MiB
313          webm       3840x2160  2160p 2026k , webm_dash container, vp9@2026k, 30fps, video only, 375.51MiB
18           mp4        640x360    360p  218k , avc1.42001E, 30fps, mp4a.40.2 (44100Hz), 40.41MiB
22           mp4        1280x720   720p  496k , avc1.64001F, 30fps, mp4a.40.2 (44100Hz) (best)

From this youtube-link I want to download video only with id 137 and audio only with id 140.

How to download the video and audio with specified format together rather than issuing youtube-dl multiple times one for downloading video and second for downloading audio.


Solution

  • This answer comes from the youtube-dl docs:

    If you want to download several formats of the same video use a comma as a separator, e.g. -f 137,140 will download both these formats, of course if they are available.

    So you can use it like this:

    youtube-dl.exe -f 133,139 https://www.youtube.com/watch?v=KkucvzJTgmY

    Then you can convert m4a to aac with

    ffmpeg -i "audio.m4a" -acodec copy "audio.aac".

    And finally join the audio with video:

    ffmpeg -i "video.mp4" -i "audio.aac" -c:v copy -c:a copy finalvideo.mp4

    It's also possible to merge both downloaded files automatically in youtube-dl by replacing , with + sign, e.g.

    youtube-dl.exe -f 133+139 --merge-output-format mp4 https://www.youtube.com/watch?v=KkucvzJTgmY

    Another example of the format specification for downloading standard videos with a ratio like 16:9 or 4:3, that are compatible with older hardware is: -f "bestvideo[height<=360][vcodec^=avc1]+bestaudio[acodec^=mp4a]" or for narrow videos use "width<=360".