How to download video by url using ffmpeg-python - python

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?

This answer worked for me
ffmpeg.input(url_to_download, ss=FROM, t=TO).output("demo.mp4", vcodec="copy", acodec="copy").overwrite_output().run()

Related

Is it possible to pipe extracted 'img%d.jpg' images from ffmpeg to another software without saving image anywhere?

I am extracting images using command:
ffmpeg -i video -r 5 img%d.jpg
and i want to pipe each image to another executable directly without saving file anywhere.
Is it possible to do so?
You can get ffmpeg to write data to stdout and then consume that with another app.
ffmpeg -i video -r 5 -c:v mjpeg -f image2pipe pipe:1 | otherapp
The 1 after pipe: is the file descriptor.

ffmpeg_python library to add a custom thumbnail to a .mp4 file using ffmpeg?

based on this post
How do I add a custom thumbnail to a .mp4 file using ffmpeg?
Using ffmpeg 4.0, released Apr 20 2018 or newer,
ffmpeg -i video.mp4 -i image.png -map 1 -map 0 -c copy -disposition:0 attached_pic out.mp4
As in version 4.2.2...See Section 5.4 in FFmpeg documentation
To add an embedded cover/thumbnail:
ffmpeg -i in.mp4 -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4
how can i do that using ffmpeg_python library
https://github.com/kkroening/ffmpeg-python/tree/master/examples
thanks
Even if the OP might not need a solution anymore, I came here to find it.
I found an example in the issues of the ffmpeg_python GitHub repository:
import ffmpeg
video = ffmpeg.input('in.mp4')
cover = ffmpeg.input('cover.png')
(
ffmpeg
.output(video, cover, 'out.mp4', c='copy', **{'c:v:1': 'png'}, **{'disposition:v:1': 'attached_pic'})
.global_args('-map', '0')
.global_args('-map', '1')
.global_args('-loglevel', 'error')
.run()
)

How to run this complex ffmpeg command in python?

I'm working on a python script to automate sound and video clip processing. So far I've been able to run ffmpeg commands in python using subprocess, e.g:
#extract video audio
subprocess.call(['ffmpeg', '-i', 'video.mp4', 'vid_audio.mp3'])
However, I can't seem to get the following command split into a list that works with subprocess.
#merge two audio tracks with scaled volume
ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a]volume=.3[A];[1:a] [A]amerge[out]" -map [out] -c:a libmp3lame -q:a 4 audiofinal.mp3
Any help on how to split the above command into a list that works with subprocess would be greatly appreciated!

Add watermark to a video using ffmpeg in python

I want to add watermark for my video, with ffmpeg i found command:
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=1500:1000" output.mp4
But it run in cli, not in python code(i cannot found). So have anyway to embbeded it to python code(not call in subprocess)?
edit: i found pyffmpeg but no guide to use it too.
from pyffmpeg import FFmpeg
ff = FFmpeg()
ff.options("-i input.mp4 -i watermark.png -filter_complex overlay=1500:10 output.mp4")

HLS - how to create a m3u8 manifest if I have ts files (Ubuntu)?

So I have found out I can create ts segments of a movie with this ffmpeg command:
ffmpeg -i foo.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list out.list -segment_time 10 out%03d.ts
But now I don't know how to create a m3u8 manifest file from ts files. Is there some open source library or command in Ubuntu that can do this for me?
If not, how difficult is it to create the m3u8 file in Python or some other language?
FFmpeg can create m3u8 files. Just use arguments 'segment_list' for playlist name and 'segment_list_type m3u8' for creating m3u8 type playlist. Just make sure you are using latest ffmpeg version.
For more info look at this section in documentation.
The latest version of ffmpeg pulled from git (tested with ffmpeg version git-2013-08-15-165b657) will generate the segment playlist file in m3u8 format if you specify the m3u8 extension for your output file when using the -segment_list argument.
ffmpeg -i foo.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list out.m3u8 -segment_time 10 out%03d.ts
ffmpeg stream segmenter reference

Categories

Resources