0

i have the following command to overlay gif above png

String command = '-y -i $path.png -i $path.gif -filter_complex '
             '[1:v]scale=200:200[i1];'
             '[0:v][i1]overlay=100:100'
             ' -q:v 1 $output.gif';

it work fine , but the problem is that my first input ($path.png) is no longer transparently as what it was before execute .

in other word : before i execute the command my path.png has rounded corners and transparently background , when i overlay the gif above it so it totally effect path.png like it remove the rounded corners and background became black .

when i overlay png instead of gif so it does not effect the path.png and everything is fine .

So how to to overlay gif with preserving the transparently of path.png and it's rounded corner too . thanks

Edit

this is the first input (png)

enter image description here

this is second input (gif)

enter image description here

Now i am trying to overlay the second input (gif) above the first input (png)

'-y -i png -i gif -filter_complex '
             '[1:v]scale=$w:$h[i1];'
             '[0:v][i1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)-10'
             ' -q:v 1 outputGif';

OUTPUT

enter image description here

as you can see , it lost the black transparently and rounded corners

and the following is @Rotem command

 '-y -i png  -i gif -filter_complex '
             '"[1:v]scale=$w:$h[i1];'
             '[0:v][i1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)-10:'
             'format=auto,split[s0][s1];[s0]palettegen=reserve_transparent=1[p];[s1][p]paletteuse" -q:v 1 outputGif'; 

output

enter image description here

it became totally transparent . but i am trying to keep that black transparent background like original and not fully transparent

1 Answers1

0

For keeping transparently for both GIF and PNG, we may use the following syntax:

ffmpeg -y -i in.png -i in.gif -filter_complex "[1:v]scale=200:200[i1];[0:v][i1]overlay=100:100:format=auto,split[s0][s1];[s0]palettegen=reserve_transparent=1[p];[s1][p]paletteuse" -q:v 1 out.gif


  • overlay=100:100:format=auto,format=rgba - forces the overlay output pixel format to be rgba (keeping transparency).
    Note: It's working with FFmpeg 5.1.2 (I didn't test older versions).
  • [s0]palettegen=reserve_transparent=1[p];[s1][p]paletteuse - generates a new palette for the output GIF as in the following answer.
    The new palette matches the colors of the new overlaid image.
    reserve_transparent=1 generates the palette with transparency.

Testing:

out.gif:
enter image description here

in.png:
enter image description here

in.gif:
enter image description here

Rotem
  • 3,346