Replace transparent pixels (alpha) with black in ffmpeg? - ffmpeg

I have an image with alpha channel indicating what the background is.
How do I de-alpha-y (remove the alpha channel) and make the background pure black with ffmpeg?

Basic syntax would be
ffmpeg -i in.png -filter_complex "color=black,format=rgb24[c];[c][0]scale2ref[c][i];[c][i]overlay=format=auto:shortest=1,setsar=1" out.png
What this does is generate a black canvas and resizes it to the image size. Then the image is overlaid on top. The opaque pixels from the image are retained but the transparent pixels reveal the canvas underneath.

Related

How can I overlay an angled gradient or fade over the corner of a video with ffmpeg?

I want to darken the corner of a video with a (for instance) 45-degree black gradient. I'd like to customize the angle, feathering, color and opacity. My video is 10-bit UHD HEVC and I need to output to 10-bit lossless intermediate (probably v210 codec). How can I do all of this in ffmpeg?
Here is a mockup of what I want to do:

FFMPEG: How do I set the transparency color of an animated GIF for overlaying on a video?

I have a video clip that I've converted to an animated GIF with ffmpeg. I would like to overlay that animated GIF onto a video clip. The problem is I can't figure out how to set the transparency color of the GIF. I want the solid black background of the GIF to be transparent.
ffmpeg -i video.mp4 output.gif
That's what I'm doing to created the animated GIF. Again, looks great. I just need to add black (#000000) as the transparent color of the GIF.
Thanks!

How to remove colour background into transparent or other colour with ffmpeg?

My video is like in this picture. I need to remove blue background into transparent or other colour. How can I make it?enter image description here

Convert grayscale image to progressive black plus transparency?

I have a grey scale image, from which I wish to convert all grey pixels into half transparent pixels, and white ones into transparent pixels.
How could I process a grey scale raster image via shell ?
Input :
Output (here made via Gimp):
Current Gimp process via GUI:
GIMP 2.6 > Load your shaded relief image (....shaded.tif : are grayscale)
or a screenshoot of your shaded relief (screenshot : RGB colors)
Force it to be RGB: Gimp > Image > Mode > RGB, click.
Delete the grey : Colors > "color to alpha" pop up > uncheck "preview", click on the horizontal color rectangle > "Color to alpha color picker" pop up> bottom right corner, click on the icon eyes dropper > choice you color of to delete (some grey pixel in a flat plain) > validate.
Delete an other color (white, black background) > same.
File > save as > ProjectName_relief_whitened.png (to keep transparency)
[note: SO images display, and image background CSS makes hard to see the subtile differences between files.]
Given the following gray scale input.png :
1a. To make black pixels of this image transparent and linearly keep the white pixels as they are, run this command:
convert source.png -alpha copy -fx '#fff' result.png
1b. To make white pixels transparent and linearly keep the black as they are, use:
convert source.png -alpha copy -channel alpha -negate +channel result.png
Manual:
convert – is the ImageMagic command (one of several)
source.png – is the greyscale source image.
-alpha copy – it copy contents of the previous file into the alpha channel.
-channel alpha – it specify that following operators only should affect the alpha channel.
-negate – it invert the current channel (channel alpha).
+channel – Specify that following operators only affect the opposite channel. For us, it switch focus from the alpha channel, to the color channel. (color channel is initially the default)
-fx '#000' – Replace current channel (for us, the color channel) contents with black pixels, so the end result actually fully depends on the alpha channel. If not included, all semi-transparent pixels in generated image will retain colors, from #FFF (white) to #000 (black).
Result of 1b:
Wiping out plains:
An additional processing could wipe out most of the flat plains, which appears around greys (#DDDDDD) with opacity:~50%. This could be done by :
convert input.png -fuzz 8% -transparent "#DDDDDD" grey_no.8pc.png
convert grey_no.8pc.png -alpha copy -channel alpha -negate +channel result.grey_no.png
so the plains avoid an useless #DDDDDD, opacity:50% overlay.
See also:
ImageMagick options: http://www.imagemagick.org/script/command-line-options.php

Image resizing, maintaing image size - beginner question

Im attempting to resize an image from 480x800 to 320x240. Below are the results. The original image has an oval shaped circle whereas the resized image has a more spherical shape. Is it possible to resize the original image so that the circle and rectangle are in their original proportions but smaller?
Can imagemagick or gimp (or other software) achieve this ?
Here's Imagemagick solution.
1) If you want large image to just fit 320x240 box and leave proportions, use:
convert test.png -size 320x240 resized.png
That will produce image sized 144x240.
http://www.imagemagick.org/Usage/resize/#resize
2) If you want large image to completely fill a specific image size, use:
convert test.png -resize 320x240\> \
-size 320x240 xc:blue +swap -gravity center -composite \
resized.jpg
That will produce image sized 320x240 with resized big image in center and blue fill on sides.
http://www.imagemagick.org/Usage/resize/#space_fill

Resources