Zend certified PHP/Magento developer

How do I do math inside an ffmpeg/youtube-dl command or use -to while having -ss before -i

Using youtube-dl and ffmpeg I’ve got downloading part of a youtube video working fine thanks to this question

ffmpeg -ss 60 -i $(youtube-dl -g -f 18 "https://youtu.be/oHg5SJYRHA0") -t 5 -c copy out.mp4

but I’d like to simplify figuring out the -t argument. Currently I do “copy video URL at current time” twice on youtube and then with a calculator do “ending second – starting second” to get the correct length. So far I’m thinking that I should either

  • somehow just paste that calculation in

so something like

ffmpeg -ss 60 -i $(youtube-dl -g -f 18 "https://youtu.be/oHg5SJYRHA0") -t $(expr 65 - 60) -c copy out.mp4

but in a way that actually works. Looked at question about doing basic math in bash but it doesn’t really cover how to do math when giving an argument.

Or

  • figure out a way to use -to instead -t in a way that doesn’t first download the entire video
ffmpeg -i $(youtube-dl -g -f 18 "https://youtu.be/oHg5SJYRHA0") -ss 60 -to 65 -c copy out.mp4

Works fine for short videos but as the 1st link at some point mentions not having -ss before -i results in downloading the entire video before it’s replaced with a cut one which is far from ideal for longer videos(ie.
ffmpeg -i $(youtube-dl -g -f 22 "https://youtu.be/n-ctMKGBt_E") -ss 38347 -to 38838 -c copy 2022-04-04_PPJT45_720p.mp4)
Based on explanation here I thought using -ss twice might work but no luck

ffmpeg -ss 60 -i $(youtube-dl -g -f 18 "https://youtu.be/oHg5SJYRHA0") -ss 00 -to 65 -c copy out.mp4

65s clip so basically same as using -t

ffmpeg -ss 60 -i $(youtube-dl -g -f 18 "https://youtu.be/oHg5SJYRHA0") -ss 60 -to 65 -c copy out.mp4

interestingly this did a 5s clip at 120s.

At this point I feel rather stuck and not really sure what more I could do to figure out how to do what I want.

In case it’s relevant I’m currently using Git BASH that Git for Windows includes to do the commands.