Add watermark to a video using ffmpeg in python - 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")

Related

How to download video by url using ffmpeg-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()

Compiling frames into a video with ffmpeg

I have a folder with a number of frames in which I'd like to concatenate into an mp4 file using ffmpeg. What is the correct syntax to do this in a Jupyter notebook script? I have tried:
os.system("ffmpeg -r 30 -i ./inputs/upload%00001d.png -y ./inputs/result.mp4")
The above runs through with no errors but does not produce an output.
As I've stated in the comment, correct your file format to upload%05d.png and consider specifying the codec too:
def saveMpeg():
os.system("ffmpeg -r 30 -i ./inputs/upload%05d.png -vcodec mpeg4 -y ./inputs/result.mp4")
saveMpeg()

Unable to execute ffmpeg command in terminal through Automator and Python [duplicate]

I am using the following system command in Python 2.7. I am able to execute the same command in terminal successfully whereas I am not able to run it in python(getting return code = 32512). The command basically converts a mp3 file into a wave file along with stereo to mono conversion. I am able to run the same command in terminal successfully.
Below is the command I'm trying out:
os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
I also tried using the subprocess command but it gave the same 32512 return code.
Could anyone help me out on what's wrong with this?
A more specific answer to this.
Instead of using the command like this in python:
os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
First try to find out where is your ffmpeg installation by giving the following command in terminal (Works on linux and mac)
which ffmpeg
In my case this was the output of the above command:
/usr/local/bin/ffmpeg
Now, modify the os.system command in python as follows:
os.system("/usr/local/bin/ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
which should work great without throwing 32512 error!
You're getting that error because you have to use the full path to the ffmpeg command with os.system().
Instead of os.system() look at subprocess.call(). This may help.

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()
)

os.system() returns error code 32512 - Python

I am using the following system command in Python 2.7. I am able to execute the same command in terminal successfully whereas I am not able to run it in python(getting return code = 32512). The command basically converts a mp3 file into a wave file along with stereo to mono conversion. I am able to run the same command in terminal successfully.
Below is the command I'm trying out:
os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
I also tried using the subprocess command but it gave the same 32512 return code.
Could anyone help me out on what's wrong with this?
A more specific answer to this.
Instead of using the command like this in python:
os.system("ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
First try to find out where is your ffmpeg installation by giving the following command in terminal (Works on linux and mac)
which ffmpeg
In my case this was the output of the above command:
/usr/local/bin/ffmpeg
Now, modify the os.system command in python as follows:
os.system("/usr/local/bin/ffmpeg -i /Users/krish/audio.mp3 -acodec pcm_s16le -ar 16000 -ac 1 /Users/krish/converted_audio.wav")
which should work great without throwing 32512 error!
You're getting that error because you have to use the full path to the ffmpeg command with os.system().
Instead of os.system() look at subprocess.call(). This may help.

Categories

Resources