I'm writing this Powershell script:
$URL = "https://www.youtube.com/watch?v=KbuwueqEJL0"
$from = 00:06:15
$to = 00:09:17
$cmdOutput = (youtube-dl --get-url $URL)
ffmpeg -ss $from -to $to -i <video_url> -ss $from -to $to -i <audio_url> output.mkv
This script's purpose is to download a part of a Youtube video. I've set the variable $URL to specify the Youtube URL, while $from
and $to
is the start and end time of the part I want to download.
$cmdOutput
is used to output the stream URL. The output would have two lines: the first one is the URL for the video stream, while the second one is the audio stream URL.
Currently, I don't know how to use the output as a variable and specify the line number of $cmdOutput to put it into the correct stream. I guess <video_url>
and <audio_url>
would be replaced by something like $cmdOutput[line 1]
, and $cmdOutput[line 2]
, though I know that those are incorrect.
I've consulted this answer, and it is handy for me to write this script. I've also read Boris Lipschitz's answer on how to do the same thing with Python, but his answer does not work.
In that script, the -ss <start_time>
flag inputs the seeking point, and the -t <duration>
flag tells FFmpeg to stop encoding after the specified duration. For example, if the start time is 00:02:00 and the duration is 00:03:00, FFmpeg would download from 00:02:00 to 00:05:00, which is not the expected outcome. For some reason, his Python script skips the first 5 seconds of output, even if I replace the -t
flag with -to <end_time>
. I've tried to edit his script, but it does not work unless you explicitly specify the time for both video and audio stream, as well as their respective stream URL.