MTALY
MTALY

Reputation: 1782

Downloading video & audio segment simultaneously with youtube-dl and ffmpeg

For an online streaming video that I would like to download I have two m3u8 files.

One for the video itself with segment-0.ts to segment-250.ts:

#EXTINF:6.000000,
segment-0.ts
#EXTINF:6.000000,
segment-1.ts
#EXTINF:6.000000,
segment-2.ts
#EXTINF:6.000000,
segment-3.ts
#EXTINF:6.000000,
segment-4.ts

and another m3u8 for the audio segments:

#EXTINF:6.016000,
segment-0.aac
#EXTINF:6.016000,
segment-1.aac
#EXTINF:6.016000,
segment-2.aac
#EXTINF:6.016000,
segment-3.aac
#EXTINF:6.016000,

So, I use youtube-dl and ffmpeg to download the both m3u8 separately then merge them to get the final mp4 (audio+video).

Is there a way to merge the files or use a combined command in the Terminal to automatically download both and merge them?

Upvotes: 3

Views: 3707

Answers (1)

martinr92
martinr92

Reputation: 718

FFmpeg can process multiple inputs:

ffmpeg -i <first> -i <second> output.mp4

Just place both URLs returned from youtube-dl:

youtube-dl -g <my-first-url>
youtube-dl -g <my-second-url>

If you are using a unix (linux/MacOS) system you can do both steps in one command:

ffmpeg -i $(youtube-dl -g <my-first-url>) -i $(youtube-dl -g <my-second-url>) output.mp4

Upvotes: 3

Related Questions