add multiple overlays to a single image with ffmpeg - image

How am I supposed to add two transition animations to the same image in the video with ffmpeg command? I want the image to slide from left to right and after a while back from right to left... This command is for left to right
ffmpeg -i input.mp4 -i image.png -filter_complex "[0:v][1:v]overlay=x='min(-1.5*w+5*w*t,5)':y=H/2-h/2'" -y output.mp4

There are two methods to do this. One is to provide a clipped oscillating function, similar to the expression for x used in the drawtext filter here.
The other method is use a conditional expression, shown below.
ffmpeg -i input.mp4 -i image.png
-filter_complex
"[0:v][1:v]overlay=x='if(lt(t,8),min(-1.5*w+5*w*t,5),5-5*w*(t-8))':y=H/2-h/2'"
-y output.mp4
Here's the slide out starts at t=8s.

Related

FFMpeg add drop shadow to a video

I have this example video, recorded by Kazam:
https://user-images.githubusercontent.com/1997316/178513325-98513d4c-49d4-4a45-bcb2-196e8a76fa5f.mp4
It's a 1022x728 video.
I need to add a drop shadow identical to the one generated by the "Drop shadow (legacy)" filter of Gimp with the default settings. So, I generated with Gimp a PNG containing only the drop shadow. It's a 1052x758 image:
Now I want to put the video over the image to get a new video with the drop shadow. The wanted effect for the first frame is:
So, the video must be placed over the image. The top-left corner of the video must be in the position 11x11 of the background image.
How can I achieve this result?
I tried without success the following command. What's wrong?
ffmpeg -i shadow.png -i example.mp4 -filter_complex "[0:v][1:v] overlay=11:11'" -pix_fmt yuv420p output.mp4
About the transparency of the PNG background image, if it can't be maintained, then it's okay for the shadow to be on a white background. Otherwise, if it can be maintained by using an animated GIF as the output format, it is better.
The solution is to remove the transparency from shadow.png. Then:
ffmpeg -i example.mp4 -filter_complex "[0:v] palettegen" palette.png
ffmpeg -loop 1 -i shadow.png -i example.mp4 -i palette.png -filter_complex "[1:v] fps=1,scale=1022:-1[inner];[0:v][inner]overlay=11:11:shortest=1[new];[new][2:v] paletteuse[out]" -map '[out]' -y output.gif
The result is exactly what I wanted:
This solution is inspired by the answer https://stackoverflow.com/a/66318325 and by the article https://www.baeldung.com/linux/convert-videos-gifs-ffmpeg

FFMPEG - crop and pad a video (keep 3840x1920 but with black borders)

I am trying to crop a video so that I can remove a chunk of the content from the sides of a 360-degree video file using FFmpeg.
I used the following command and it does part of the job:
ffmpeg -i testVideo.mp4 -vf crop=3072:1920:384:0,pad=3840:1920:384:0 output.mp4
This will remove the sides of the video and that was initially exactly what I wanted (A). Now I'm wondering if it is possible to crop in the same way but to keep the top third of video. As such, A is what I have, B is what I want.:
I thought I could simply do this:
ffmpeg -i testVideo.mp4 -vf crop=3072:1920:384:640,pad=3840:1920:384:640 output.mp4
But that doesn't seem to work.
Any input would be very helpful.
Use the drawbox filter to fill cropped portion with default colour black.
ffmpeg -i testVideo.mp4 -vf drawbox=w=384:h=1280:x=0:y=640:t=fill,drawbox=w=384:h=1280:x=3840-384:y=640:t=fill -c:a copy output.mp4
The first filter acts on the left side, and the 2nd on the right.

FFMPEG curtain effect slideshow from images

I have bunch of images that i have to convert to slideshow with curtain effect. currently i am running this command that convert images to video.
ffmpeg -r 1/5 -i img%d.png -c:v libx264 -vf "fps=25,format=yuv420p" video.mp4
But how to achieve this kind of effect with ffmpeg. Image link Required result
I searched online but not found any solution. I have clue of alpha mask but no idea how to use it for such result.
ffmpeg -y -i img1.png -i img2.png -i img3.png -filter_complex "[0:v]zoompan=z='zoom+0.0000':d=50[img1];[1:v]zoompan=z='if(lte(zoom,1.0),1.1,max(1.001,zoom-0.0030))':d=200[img2];[img1][img2]blend=all_expr='if(lte((H/2-sqrt((Y-H/2)*(Y-H/2)))+N*8*SH,H/2),A,B)'[img1img2];[1:v]zoompan=z='zoom+0.0000':d=50[img2];[2:v]zoompan=z='if(lte(zoom,1.0),1.1,max(1.001,zoom-0.0030))':d=200[img3];[img2][img3]blend=all_expr='if(lte((H/2-sqrt((Y-H/2)*(Y-H/2)))+N*8*SH,H/2),A,B)'[img2img3];[img1img2][img2img3]concat=n=2[final]" -map "[final]" out.mp4
This ffmpeg command will generate door open (curtain) effect.
Here is logic.
Suppose you have there images you want to create this effect. First create blend effect of first img1 and img2. Then create another blend effect with img2 and img3. then merge these 2 generated videos.

Tile filter for libav/avconv

Is there some way to use libav/avconv to duplicate the effect of the tile filter in FFMPEG?
I'm trying to create a strip of images from left to right with one image for every ten seconds of video input.
My plan is to first generate the images and then create the image strip. Preferably I want to use libav over ffmpeg. So far I have created this:
avconv -i video.mp4 -vf scale=320:-1,fps=1/10 -q:v 6 img%03d.jpg
which creates the images. But then I only know how create the image with ffmpeg using:
ffmpeg -i img%03d.jpg -filter_complex tile=6x1 output.jpg
So if anyone has any tips on how to rewrite the just the second or both commands to use avconv I welcome any advise :)
As libav/avconv did not have any filters supporting my requirements in any easy way switching to a static build of ffmpeg was the simplest solution.
The commands then became:
ffmpeg -i video.mp4 -vf scale=320:-1,fps=1/10 -q:v 6 img%03d.jpg
and
ffmpeg -i img%03d.jpg -filter_complex tile=6x1 output.jpg

Which filter should be used when i want to add watermark to a video?

Hi everyone,
I want to add a watermark to a video use a picture.
here is the problem
and this is my command:
c:\ffmpeg.exe -y -i c:\ffmpeg\input\walk.mp4 -acodec copy -b 300k -vf "movie=w1.jpg [watermark];[in][watermark] overlay=5:5 [out]" c:\ffmpeg\output\walk.mp4
What am I doing wrong?
You can use the overlay filter, but first you need to use a recent build because the version you are using is considered to be absolutely ancient due to how active the FFmpeg project is. You can get builds for Windows at Zeranoe FFmpeg builds.
Now that you are not using a graybeard ffmpeg here is the most basic example:
ffmpeg -i background.avi -i watermark.jpg -filter_complex overlay output.mp4
The overlay filter documentation will show how to position the watermark. This example will place the watermark 10 pixels from the bottom right corner of the main video and copy your audio as in your example:
ffmpeg -i background.avi -i watermark.jpg -filter_complex overlay=main_w-overlay_w-10:main_h-overlay_h-10 -codec:a copy output.mp4

Resources