1
votes

I am trying to script the creation of videos using ImageMagick to create some overlays which are then placed on top of a video.

If I try to use the image created by ImageMagick directly the transparency is drawn as opaque.

I have created a transparent PNG using ImageMagick draw commands. When loaded into GIMP and examined, the PNG has an alpha channel and each transparent pixel appears to have transparency: RGBA = 0,0,0,0

This image when then used as an overlay in ffmpeg just has an opaque black background in the video.

If I export the image again from GIMP then the file looks identical, but in the video just appears as a solid blue (the colour of the drawings in the overlay image).

I can fix this by taking the overlay image, loading it in GIMP and then selecting all and creating a new image from the clipboard and exporting that (using exactly the same settings as when I re-exported before without creating a new file) and it will then work exactly as desired, showing the non-transparent portions of the overlay and not showing transparent parts.

KEY QUESTION:

How can I either script the conversion that somehow occurs when creating a new file in GIMP, or (much better) not have it go wrong in the first place?

Here are the two files:

BROKEN: This does not work WORKS: This one does work What is the difference?

1
Why not take the image steaight from ImageMagick into ffmpeg and avoid gimp if that messes it up? - Mark Setchell
Sorry if I was unclear, but what I meant to get across was that the original png output from ImageMagick was broken, the png opened and re-exported from GIMP was even more broken, but the thing that worked in the end was select all and copying and pasting into a new image in GIMP. I only started using GIMP once (for no apparent reason) the ImageMagic output became unusable. - user2711915
I am not at my Mac to test this but try preceding the output filename in ImageMagick with PNG32: like this convert xyz.png ... PNG32:output.png - Mark Setchell
Yes, that looks like it works, fantastic. If you will put it in as an answer I'll accept it. - user2711915

1 Answers

2
votes

I suggest you prefix the output filename when using ImageMagick with PNG32: to force it to generate a 32-bit ber pixel image - i.e. 1 byte each for R, G, B and Alpha and hope that ffmpeg is happier with that.

convert input.png -draw ... PNG32:output.png

If you run identify -verbose (also in the ImageMagick suite) on your broken and your working images, you will see that the primary difference is that the working image has color-type=6 and bit-depth=8 whereas the broken image has color-type=3 (indexed) and bit-depth=4

enter image description here