3

If I download a video using youtube-downloader I can watch the part file while downloading (in my case using mpv). Suppose I cannot or don't want to select a format containing both video and audio then the audio in the part file is missing because it is downloaded and merged after the video download is complete.

Is there any fast way to get audio and video merged during the download, such that I can watch the part file including audio.

I already asked a similar question on github and learned that I could use the --downloader ffmpeg option. This works, but is very slow, so I am looking for a faster way to do it.

The problem occurs if I download very large video (for example 10 hours long) in a high quality. However downloading audio is much much faster. So suppose I have the audio file already and I am downloading the video file. Is there an indirect way (workaround) using for example ffmpeg to merge the audio continuously into the video while the file is downloading.

2 Answers 2

2

Option 1: You can select a video download format that contains a mixed/muxed stream of both video and audio.

For example,

yt-dlp -F https://youtu.be/3QnD2c4Xovk

will list formats to choose, and something like

yt-dlp -f 18 https://youtu.be/3QnD2c4Xovk

will choose that format. The partial file contains video and audio if the format supports it.

Option 2: You can also choose to download two formats, one each for audio and video which will then be muxed by yt-dlp:

yt-dlp -f 251,244  https://youtu.be/3QnD2c4Xovk

The format I specified first (here, 251) was downloaded first in my tests and I could listen right away by playing the partial file.


For completeness: the above currently outputs

yt-dlp -F https://youtu.be/3QnD2c4Xovk
[youtube] Extracting URL: https://youtu.be/3QnD2c4Xovk
[youtube] 3QnD2c4Xovk: Downloading webpage
[youtube] 3QnD2c4Xovk: Downloading ios player API JSON
[youtube] 3QnD2c4Xovk: Downloading android player API JSON
[youtube] 3QnD2c4Xovk: Downloading m3u8 information
[info] Available formats for 3QnD2c4Xovk:
ID  EXT   RESOLUTION FPS CH │   FILESIZE  TBR PROTO │ VCODEC         VBR ACODEC      ABR ASR MORE INFO
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
sb2 mhtml 48x27        0    │                 mhtml │ images                                 storyboard
sb1 mhtml 67x45        0    │                 mhtml │ images                                 storyboard
sb0 mhtml 135x90       0    │                 mhtml │ images                                 storyboard
233 mp4   audio only        │                 m3u8  │ audio only         unknown             [en] Default
234 mp4   audio only        │                 m3u8  │ audio only         unknown             [en] Default
139 m4a   audio only      2 │    1.84MiB  48k https │ audio only         mp4a.40.5   48k 22k [en] low, m4a_dash
249 webm  audio only      2 │    2.22MiB  57k https │ audio only         opus        57k 48k [en] low, webm_dash
250 webm  audio only      2 │    3.02MiB  78k https │ audio only         opus        78k 48k [en] low, webm_dash
140 m4a   audio only      2 │    4.91MiB 127k https │ audio only         mp4a.40.2  127k 44k [en] medium, m4a_dash
251 webm  audio only      2 │    5.82MiB 151k https │ audio only         opus       151k 48k [en] medium, webm_dash
17  3gp   176x144     12  1 │    2.17MiB  56k https │ mp4v.20.3          mp4a.40.2       22k [en] 144p
394 mp4   216x144     24    │    1.26MiB  33k https │ av01.0.00M.08  33k video only          144p, mp4_dash
269 mp4   216x144     24    │ ~  4.53MiB 115k m3u8  │ avc1.4D400C   115k video only
160 mp4   216x144     24    │  717.16KiB  18k https │ avc1.4D400C    18k video only          144p, mp4_dash
603 mp4   216x144     24    │ ~  5.39MiB 136k m3u8  │ vp09.00.11.08 136k video only
278 webm  216x144     24    │    1.34MiB  35k https │ vp09.00.11.08  35k video only          144p, webm_dash
395 mp4   360x240     24    │    1.41MiB  37k https │ av01.0.00M.08  37k video only          240p, mp4_dash
229 mp4   360x240     24    │ ~  6.73MiB 170k m3u8  │ avc1.4D400D   170k video only
133 mp4   360x240     24    │    1.11MiB  29k https │ avc1.4D400D    29k video only          240p, mp4_dash
604 mp4   360x240     24    │ ~  9.56MiB 242k m3u8  │ vp09.00.20.08 242k video only
242 webm  360x240     24    │    1.58MiB  41k https │ vp09.00.20.08  41k video only          240p, webm_dash
396 mp4   540x360     24    │    2.13MiB  55k https │ av01.0.01M.08  55k video only          360p, mp4_dash
230 mp4   540x360     24    │ ~ 16.81MiB 425k m3u8  │ avc1.4D4015   425k video only
134 mp4   540x360     24    │    2.31MiB  60k https │ avc1.4D4015    60k video only          360p, mp4_dash
18  mp4   540x360     24  2 │ ≈  7.36MiB 186k https │ avc1.42001E        mp4a.40.2       44k [en] 360p
605 mp4   540x360     24    │ ~ 19.08MiB 482k m3u8  │ vp09.00.21.08 482k video only
243 webm  540x360     24    │    2.66MiB  69k https │ vp09.00.21.08  69k video only          360p, webm_dash
397 mp4   720x480     24    │    3.21MiB  83k https │ av01.0.04M.08  83k video only          480p, mp4_dash
231 mp4   720x480     24    │ ~ 29.80MiB 753k m3u8  │ avc1.4D401E   753k video only
135 mp4   720x480     24    │    4.36MiB 113k https │ avc1.4D401E   113k video only          480p, mp4_dash
606 mp4   720x480     24    │ ~ 28.21MiB 713k m3u8  │ vp09.00.30.08 713k video only
244 webm  720x480     24    │    4.21MiB 109k https │ vp09.00.30.08 109k video only          480p, webm_dash

and you can see the "audio only" and "video only" description text by the yt-dlp tool.

2

Expanding upon Ned64's answer, you can start the downloads like this:

yt-dlp -f 'bestaudio[ext=m4a],bestvideo[ext=mp4]' 'https://www.youtube.com/watch?v=2tdiKTSdE9Y'

After completing download of the audio and while still downloading the video, you can use mpv's --audio-file option:

mpv --audio-file="*[2tdiKTSdE9Y].m4a" "*[2tdiKTSdE9Y].mp4.part"

It probably works with the ogg and webm variants, too.

2
  • For me running mpv on the ....part file works right away without any parameters.
    – Ned64
    Commented Aug 4, 2023 at 22:28
  • I usually prefer that method, too (format 22). However, OP stated "I cannot or don't want to select a format containing both video and audio". They would watch the video without audio.
    – Hermann
    Commented Aug 5, 2023 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .