0

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.

  • Can you give an example of the value for ```$cmdOutput``` (you can add ```write-host $cmdOutput``` to see it displayed in the console output) and what you'd expect the values for `````` and `````` to be as a result? (Update your question with the information rather than reply in comments). – mclayton Jul 14 '21 at 08:54
  • @mclayton For example, I want to get the stream URL for the youtube video above. I would use `youtube-dl --get-url https://www.youtube.com/watch?v=KbuwueqEJL0` to get the URL for the streams and the program would output two lines with two different URLs, one for the video stream and one for the audio stream. [This is the output](https://paste.ubuntu.com/p/NzqdDYT2Dd/) I would get. – Nguyễn Đức Minh Jul 14 '21 at 09:00
  • @mclayton If you look at the third paragraph after the script's code block, you should find my example about `$cmdOutput` there. – Nguyễn Đức Minh Jul 14 '21 at 09:02
  • I don't have the ```youtube-dl``` module installed locally, so I can't run your script to get the output. If you can post the *actual values* you might find someone is able to help, but I'm not personally able to assist any further without concrete values in your question... – mclayton Jul 14 '21 at 09:33

0 Answers0