youtube-dl and ffmpeg under windows #029

To get youtube-dl for windows visit youtube-dl.org , choose youtube-dl.exe
Requires Microsoft Visual C++ 2010 Redistributable Package (x86) , get it here  link
To get ffmpeg for windows visit  www.ffmpeg.org/download.html , choose "windows builds by Zeranoe"


Place files in the same folder, both these apps run in a command line under windows, however youtube-dl for windows stability is quite worse then its linux(in arch) counterpart. The process of  downloading streams from twAtch or youtObe process is the same.
To compensate for the noticeable instability under M$Windows OS its better to download large streams by using ffmpeg, and by spliting them into parts.

Here are the step by step commands:


youtube-dl --list-formats https://www.twatch.tv/videos/999999999
^ use one of the formats after the -f parameter in the following command(example 720p)

youtube-dl -f 720p -g https://www.twatch.tv/videos/999999999
^ this will generate an url with the stream/video, copy it, paste it after the -i between "", example:

ffmpeg -i "https://vod-secure.twitch.tv/xxxxxxxxx/720p30/index-dvr.m3u8" -f segment -segment_time 600  -c copy  -y part_a_%03d.mp4

the -segment_time 600 is 600 seconds, 10minutes

if a download fails, you can resume the download based on the number of completed parts, so if you have 10 parts completed of a long stream you have 10 * 10 minutes = 60 + 40minutes = 1h40m
ffmpeg -ss 1:40:00 -to 5:00:00 -i https://vod-secure.twitch.tv/xxxxxx/720p30/index-dvr.m3u8 -f segment -segment_time 600  -c copy  -y part_a_%03d.mp4

the -to sets the time limit


with alot of 10min videos the command to merge or concat them requires the user to create a text file with this format :

file 'part_a_001.mp4"
file 'part_a_002.mp4"
(...)
#file 'part_a_099.mp4" -- this is a commented line, will be ignore

now to auto generate this list under windows, the following command is used:
for %i in (part_a_???.mp4) do echo file '%i' >> files_to_concat.txt

and then concat the files with:
ffmpeg -v verbose -f concat -safe 0 -i files_to_concat.txt -c copy  Stream_part_a.mp4

note: if the download was halted, and then other output file were used only the order in the file used to concat is significant:

for %i in (part_a_???.mp4) do echo file '%i' >> concat_list.txt
for %i in (part_b_???.mp4) do echo file '%i' >> concat_list.txt

the correct order will be created in the final file.

to update youtube-dl.exe from the command line use:
youtube-dl -U

when using specific formats with youtube-dl and splitting audio and video streams use the following command to merge them:
ffmpeg -i video_file.mp4 -i audio_file.m4a -c copy video_and_audio.mp4

update 06/2021 (updated Visual C++ 2010 x86 Redist. link)

Comments