1

I'm trying to write script that will be downloading part of youtube video by url. I'm using ffmpeg + ffmpeg-python library.

I have terminal command that I want put to python code.

ffmpeg -i "url_to_download" -ss 00:00:15 -t 00:00:25 -c:v copy -c:a copy "demo.mp4"

url_to_download is an youtube stream url that I get like in an answer to another question https://stackoverflow.com/a/57134397/6583203

I started writing script

import ffmpeg

FROM = "00:00:15"
TO = "00:00:25"
TARGET = "demo.mp4"

ffmpeg.input(url_to_download, ss=FROM, t=TO)

But I don't know how to pass parameters -c:v copy -c:a copy "demo.mp4" to ffmpeg.input

Do not advice me to use subprocess. I have the same error like in a following question: Python ffmpeg won't accept path, why?

puf
  • 359
  • 3
  • 13
  • 1
    Try: `ffmpeg.input(url_to_download, ss=FROM, t=TO).output("demo.mp4", vcodec="copy", acodec="copy").overwrite_output().run()` – Rotem Nov 15 '22 at 09:20
  • @Rotem It works, thanks! You can write this as an answer, I will accept it – puf Nov 16 '22 at 20:50
  • @Rotem if you will add link where I can read about it more, it would be helpful too – puf Nov 16 '22 at 20:53
  • There are 2 or 3 formal documentation pages - just use Google. Most of the information is found in FFmpeg documentation, but getting from FFmpeg command line syntax to ffmpeg-python requires some practice. – Rotem Nov 16 '22 at 20:57

1 Answers1

1

This answer worked for me

ffmpeg.input(url_to_download, ss=FROM, t=TO).output("demo.mp4", vcodec="copy", acodec="copy").overwrite_output().run()
puf
  • 359
  • 3
  • 13