ffmpeg -- How do I overlay a PNG over another PNG?
Solution 1
If you want to overlay A on top of B, you need to switch either the file input order or the overlay ingest order.
ffmpeg -i B.png -i A.png -filter_complex "[1]scale=iw/2:-1[b];[0:v][b] overlay" out.png
Solution 2
thia answer is not using ffmpeg yet... (i try to achieve the same but with a huge amount of images and oputput to a video file) but...
using the convert and composite command from imagemagick could help, the result is an animated gif, mpeg or either a single image.
this creates an animated gif with "overlay":
convert -delay 100 -loop 0 *.png test.gif
this will result in an mpeg file:
convert *.png test.mpeg
(anyway, for the mpeg file convert also runs ffmpeg :)
to just write an overlayed image file from multiple input files, you could use composite command from imagemagick:
composite -gravity center a.png b.png out.png
this overlays b.png (e.g. background) with a.png (e.g. foreground) preserving transparency. the output is written to out.png
or use more input images, the last one is the output image:
composite -gravity center a.png b.png c.png out.png
http://www.imagemagick.org/Usage/compose/
Related videos on Youtube
Sibbs Gambling
Updated on September 18, 2022Comments
-
Sibbs Gambling almost 2 years
I have PNG
A
with alpha layer, which I want to overlay on top of another PNGB
. How do I do that withffmpeg
?I tried
ffmpeg -i A.png -i B -filter_complex "[0:v][1:v] overlay=0:0" out.png
, but I only seeB
.Here is the command output.
> frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A > speed=0.0883x video:2169kB audio:0kB subtitle:0kB other streams:0kB > global headers:0kB muxing overhead: unknown ffmpeg version > N-83044-g2a293ec Copyright (c) 2000-2017 the FFmpeg developers built > with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configuration: > --prefix=/data/local/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/data/local/ffmpeg_build/include > --extra-ldflags=-L/data/local/ffmpeg_build/lib --bindir=/data/local/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 55. 43.100 / 55. 43.100 libavcodec 57. 72.100 / 57. 72.100 libavformat 57. 62.100 / 57. 62.100 libavdevice 57. 2.100 / 57. 2.100 libavfilter 6. 68.100 / > 6. 68.100 libswscale 4. 3.101 / 4. 3.101 libswresample 2. 4.100 / 2. 4.100 libpostproc 54. 2.100 / 54. 2.100 Input #0, png_pipe, from '/data/output/067_90.png': > Duration: N/A, bitrate: N/A > Stream #0:0: Video: png, rgba(pc), 2560x1440, 25 tbr, 25 tbn, 25 tbc Output #0, image2, to > '/data/output/067_90_down2.png': > Metadata: > encoder : Lavf57.62.100 > Stream #0:0: Video: png, rgba, 1280x720, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc > Metadata: > encoder : Lavc57.72.100 png Stream mapping: Stream #0:0 -> #0:0 (png (native) -> png (native)) Press [q] to stop, [?] for help frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A > speed=0.163x video:134kB audio:0kB subtitle:0kB other streams:0kB > global headers:0kB muxing overhead: unknown
-
Sibbs Gambling over 7 yearsThanks, but I added the two options, but it's still not working.
-
Sibbs Gambling over 7 yearsThanks, but I just tried, still to no avail. :-(
-
Gyan over 7 yearsCan you add
-report
and run my command? Link to the report generated. -
Sibbs Gambling over 7 yearsThere you go -- s000.tinyupload.com/index.php?file_id=71172992522639780031. Thanks again for your help!
-
Gyan over 7 yearsYou want 065_0 to be on top of 065?
-
Sibbs Gambling over 7 yearsThat's right! :-)
-
Gyan over 7 yearsAssuming the alpha layer isn't all black, use the edited cmd.
-
Sibbs Gambling over 7 yearsIt works now! Thanks a lot! Could you kindly also explain
[1]...[b]
andoverlay
? Can I in general combine many commands into one? -
Gyan over 7 yearsYour overlay image is twice the size of the base image, so I inserted a scale filter to downsize it.
[1]
is short for 'pick the best matching stream' ([1:v]
is short for pick the best matching video stream - same thing in this case) and[b]
is the label for the scale output which is then fed to the overlay.