FFMpeg add drop shadow to a video - ffmpeg

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

Related

ffmpeg overlay video on image and remove video black background

Im using this ffmpeg command to overlay a video on image (with remove black background):
ffmpeg -loop 1 -i image.png -i video.mp4 -filter_complex [1:v]colorkey=0x000000:0.1:0.1[ckout];[0:v][ckout]overlay[out] -map [out] -t 5 -c:a copy -c:v libx264 -y result.mp4
But as you can see in the picture, the black parts of the ball have also disappeared. How can I solve this problem?
Not possible with colorkey/chromakey alone. The background is too similar to the color you want to remove. You have two options.
Mask
Use a mask. If the video comes with an alpha mask you can use it to cut out the background using the alphamerge filter:
ffmpeg -i bg.jpg -i video.mp4 -i alpha.mp4 -filter_complex "[1][2]alphamerge[alf];[0][alf]overlay" output.mp4
Use a different color
Replace the video that has a color that is different than the color you want to remove.

Rotate text in ffmpeg [duplicate]

I am trying to overlay some text on video using ffmpeg. I am able to overlay text by the bellow command.
ffmpeg -i input1.mp4 -filter_complex "[0:v]transpose=2[anticlockwiserotated];[anticlockwiserotated]drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf: text='Test Text':x=100: y=50: fontsize=36: fontcolor=white:[textapplied];[textapplied]transpose=1" output_video.mp4
It is allowing me to overlay horizontally or vertically only.
But I want to append it with some angle like 45 degrees.
For that if I modify the command as
ffmpeg -i input1.mp4 -filter_complex "[0:v]rotate=45*PI/180[anticlockwiserotated];[anticlockwiserotated]drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf: text='Test Text':x=100: y=50: fontsize=36: fontcolor=white:[textapplied];[textapplied]rotate=315*PI/180" output_video.mp4
By this I am getting overlay video as:
Because in this first I am rotating video to 45 degrees, appending text and bringing it back to original position. So I am loosing borders.
Please suggest me the best way to overlay text with required angle on video.
Thanks in advance.
Basic method is to generate text on a blank canvas, then an alpha layer for the text, rotating the result and overlaying that on the main video.
In the command below, a should be replaced by the angle. The co-ordinates for the drawtext are used in the overlay instead. Depending on the length of your text, some of it may get clipped if you've rotated it anticlockwise. So check and adjust the Y offset accordingly.
ffmpeg -i input1.mp4 -filter_complex
"color=black:100x100[c];
[c][0]scale2ref[ct][mv];
[ct]setsar=1,drawtext=fontfile=../../public/fonts/Roboto-Regular-webfont.ttf:
text='Test Text':fontsize=36:fontcolor=white,split[text][alpha];
[text][alpha]alphamerge,rotate=a:ow=rotw(a):oh=roth(a):c=black#0[txta];
[mv][txta]overlay=x='min(0,-H*sin(a))+100':y='min(0,W*sin(a))+50':shortest=1"
output_video.mp4
One method is by using ASS or SRT subtitles with the FFmpeg subtitles or ass filters.
ffmpeg -i input -filter_complex "subtitles=diagonal.ass" output
SRT subtitles are much simpler than ASS and don't support rotation, but you can manually add it with the filter:
ffmpeg -i input -filter_complex "subtitles=diagonal.srt:force_style='Angle=45'" output
You can create and style the subtitles with Aegisub or manually.

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.

panning and zooming multiple images with ffmpeg

I have multiple images that I want to fade and zoompan for each image but when I do what others have said, the first image works perfect and the second is black. I want to have 25 images and the same thing occurs with every image black except the first one. I am sure I am missing something elementary. Please help.
ffmpeg -r .1 -i image_1.jpg -i image_2.jpg -vf "zoompan=z='min(zoom+0.0015,1.5)':d=125,fade=t=in:st=0:d=0.5,fade=t=out:st=4.5:d=0.5" -pix_fmt yuv420p output.mp4
Try using making a complex filtergraph similar to the following
-filter_complex "[0:v] panzoom, fadeout [scene1]; [1:v] panzoom, fadeout [scene2]; [scene1][scene2] concat=n=2 [output]" -map "output" output.mp4

Resources