L
L
Leonid2021-06-18 16:41:47
fmpeg
Leonid, 2021-06-18 16:41:47

How to overlay video on image using ffmpeg?

There is a video with a height of 720 and a different but known width.
it is necessary to impose on the picture 1280 by 720 in the middle.

I found examples but they are much more complicated than necessary. In this case, all sizes, indents, etc. are known, since the overlay will be performed programmatically and everything you need can be calculated and already inserted into the ffmpeg command

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Brendan Castaneda, 2021-06-30
@caballero

I thought it was not a bad idea and wrote a bat file.
: - Colon is used to separate values.
; - The filter graph consists of a sequence of filter chains. A sequence of filter chains is represented by a list of filter chain descriptions separated by ";".
, - A filter chain consists of a sequence of linked filters, each linked to the previous one in the sequence.
A filter chain is represented by a list of filter descriptions separated by ",".
scale2ref - Scale (resize) the input video based on the reference video (the image in our case).
filter_complex - Combines filters into one.
overlay- Overlay one video on top of another video or image.
It has two entrances and one exit. The first input is the "main" video overlaid with the second input.
1.1 - Image scaling value.
A value of 1 will result in a 1:1 image scaling of the video.
A value of 2 will scale the image by 2x.
Image size doesn't matter. The image is scaled relative to the video size.
The video remains static and its dimensions do not change.
Folder structure for this bat file.
your folder
|
| ffmpeg.exe
| JPG + MP4 = Watermark.bat
|
+---Result
|
|
\---Your_files
your_image.jpg
your_video.mp4

@echo off
setlocal EnableDelayedExpansion
color a
set a=Your_files\*.mp4
set aa=Your_files\*.jpg
set b="Result\temp1.mp4"
set c=ffmpeg
set f=-filter_complex "[1][0] scale2ref=w=oh*mdar:h=ih*1.1 [foto][video];[foto][video] overlay=(main_w-w)/2:(main_h-h)/2 " -preset ultrafast
for %%s in (%aa%) do !set aud="%%s"!
for %%a in (%a%) do (%c% -y -i "%%a" -i %aud% %f% %b%)
exit

I have a project dedicated to FFMPEG
There are many ready-made solutions in this repository.
You can also find more detailed instructions inside the .bat files.
Hope this solution helps you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question