ffmpeg how to place still image over full vstack? - ffmpeg

Im trying to build a simple video editor and im using ffmpeg on the background. I want as much different filters/properties in one command but im not succeeding in placing a still image before everything else (first frame). I want a vstack after the image has shown in a video.
I tried a lot of different commands etc. and most of the time the video renders but the image included in the vstack, or the video doesn't start for the amount of seconds I want the still image to be shown.
ffmpeg -hide_banner -i "header.jpg" -i "video.mp4" -i "footer" -i "still-image.jpg" -filter_complex "[1][3]overlay=0:0:enable='between(t,0,4)';vstack=inputs=3" -pix_fmt yuv420p -c:a copy -y output.mp4
Most of the time I don't get an error. It just isn't doing what's expected. The above command is one of the many I tried but is basically what I want. Can someone help please?

There are several ways to do this. This method delays the vstack and overlays still-image.jpg during the delay.
ffmpeg -i "header.jpg" -i "video.mp4" -i "footer.jpg" -i "still-image.jpg" -filter_complex "[0][1][2]vstack=inputs=3[v0];[v0]tpad=start_duration=4[bg];[bg][3]overlay=(W-w)/2:(H-h)/2:enable='between(t,0,4)',format=yuv420p[v];[1:a]adelay=4s:all=true[a]" -map "[v]" -map "[a]" output.mp4
Requires FFmpeg 4.2 or newer.

Related

ffmpeg: Is there a way to create video from images and overlay on image at same time?

I am trying to create a video from still images using ffmpeg. The command I use to do this is
ffmpeg -y -r 3 -i input_images%03d.png -c:v libx264 -vf fps=24 -pix_fmt yuv420p output.mp4
However, I would like to overlay this video on still image, without creating a video of the still image first. So, for example, if I have the following images
[still, frame1, frame2, frame3]
I'd like a command to create a video of frame1, frame2, and frame3 overlayed on still.
all with one command. Is there a way to do this?
I've looked at several answers to related problems (e.g., Add image overlay on video FFmpeg) but they don't answer my question, exactly.
Use
ffmpeg -framerate 24 -i still.png -framerate 3 -i input_images%03d.png -c:v libx264 -filter_complex "overlay=x='(W-w)/2':y='(H-h)/2'" -pix_fmt yuv420p -y output.mp4

How to combine a video and an image using "reverse" vstack?

I have an image and a video (same width). I now want to use ffmpeg to add the image above the video. Google and other SO threads the use of the vstack filter_complex tag, which works great - except that it puts the image under the video.
I've tried putting the image first and then the video, but this doesnt work. I've also tried giving the vstack command reverse inputs, but also didnt work!
The video may also contain audio which I would need to keep.
See code below:
// Works, but puts image below video (instead of above)
ffmpeg -i test.mp4 -i text.png -filter_complex vstack result.mp4
// Doesn't work at all
ffmpeg -i test.mp4 -i text.png -filter_complex '[1:v][0:v]vstack' result.mp4
// Doesn't work at all
ffmpeg -i test.mp4 -i text.png -filter_complex '[1:v][0:v]vstack=inputs=2[v]' -map '[v]' -map 0:a result.mp4
Google / SO did not yield any tips on how to achieve this so far. Do you know a solution?
Use
ffmpeg -i test.mp4 -i text.png -filter_complex '[1:v][0:v]vstack' -c:a copy -pix_fmt yuv420p result.mp4
Videos and images can have different pixel formats. When the various inputs to a stack filter don't have the same format, the filter picks the format of the first input and converts all other inputs to that format. However, some video players don't support a wide variety of formats. yuv420p is the widely supported format and so the command above forces the output to that one. Audio, if present in the MP4, will get carried over.
ffmpeg -i test.mp4 -i text.png -filter_complex '[1:v]format=yuv444p[img];[img][0:v]vstack' -c:a copy -pix_fmt yuv420p result.mp4

overlay audio volume histogram over static image

I'm actually working to a project for music video generation using ffmpeg.
I'd like to know if it's possibile to use ffmpeg itself or a combination of command line component under windows environment to make a visualization of audio spectrum (ahistogram ?) over a static background image like the one I found on the web:
Any ideas or coding tips?
ffmpeg -loop 1 -i background.png -i music.mp3 -filter_complex "[1]ahistogram=s=789x50:rheight=1[fg];[0][fg]overlay=(W-w)/2:H-h-10:shortest=1,scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v]" -map "[v]" -map 1:a -movflags +faststart output.mp4
Not exactly what you want, there is no option to create bars as in your image, but perhaps this will be good enough. See the ahistogram filter documentation for more options.

Ffmpeg video overlay

I am trying to create a video output from multiple video cameras.
Following the example given here Presenting more than 2 videos using FFmpeg
and other similar examples.
but Im getting the error
Output pad "default" for the filter "src" of type "buffer" not connected to any destination
when i run
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih[a];[a][1:0]overlay=w[b];[b][2:0]overlay=w:h" -shortest output.mp4
Im not really sure what this means or how to fix it.
Any help would be greatly appreciated!
Thanks.
When using the "padding" option, you have to specify which is the size of the output image and where you want to put the input image
[0:0]pad=iw*2:ih:0:0
tested under windows 7 with file of same size
ffmpeg -i out.avi -i out.avi -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[a][1:0]overlay=w" -shortest output.mp4
and with WebCam Cap (vfwcap) and a still picture (as i have only o=1 WebCam). BTW you can see how to scale one the source to fit in the target (just in case your source have different resolution)
ffmpeg -y -f vfwcap -r 10 -i 0 -loop 1 -i photo.jpg -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[1:0]scale=640:480[b];[a][b]overlay=w" -shortest output.mp4
under Linux:
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih:0:0[[a];a][1:0]overlay=w" -shortest output.mp4
if it doesn't work test a simple record of video 1 and after of video 0 and check their properties (type, resolution, fps).
ffmpeg -i /dev/video1 -shortest output1.mp4
ffmpeg -I output1.mp4
If you still have issue, update your question with ffmpeg console output (as text) for video and video 0 capture and also of the call with the overlay

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