Odd Couple
Greening
ImageMagick can also help you adapt existing footage for your transitions.
Say you have footage of an actor dancing in front of a green screen. First, the same way Kdenlive can load a sequence of images and use it like a clip, you can do the opposite: Load a movie clip and have Kdenlive render it as a sequence of PNG images. You can then use ImageMagick to turn the green part into a transparent backdrop and then cut out the action so you can use it for your transition.
To generate a sequence of images you can later process with ImageMagick, first load the green screen footage into Kdenlive and put it onto a track in your project. Press Render, and, in the dialog, scroll down through the Format list on the Render project tab until you reach the Image sequence section. Choose PNG, because this image format has an alpha channel (i.e., transparency) built in. Choose where you want to render and the base name of the images, and click on Render to File. Kdenlive will split your footage into convenient images, at one image per frame.
ImageMagick has two functions that can help you get the images ready for customtransition.sh
: -fill
and -trim
. The -fill
function can change a preexisting color in an image to another color of your choice. If you feed -fill
the "color" none
, it makes the pixels transparent.
Before you start, though, check the color of the green screen in one of your frames. I use KDE's KColorChooser for this. In the image shown in Figure 9, the green is not a pure #00ff00m, but rather #13ff09. Not all pixels are going to be the exact same green either, so you can use the -fuzz
option to give ImageMagick a larger amount of greens to work with:
convert frame000.png -fuzz 40% -fill none -opaque "#13ff09" alpha_frame000.png

This will change most, if not all, of the green pixels in the first frame of the sequence transparent.
ImageMagick's -trim
function tries to crop an image automatically by cutting off monochrome parts of the background. Because all of the pixels surrounding the actor are now transparent,
convert alpha_frame000.png -trim alpha_cropped_frame000.png
will cut off the parts surrounding the actor that are not filled with a color.
You can mush both functions into one command and put it into a loop to process a whole directory full of frames:
for i in frame0*.png; do convert $i -fuzz 40% -fill none -opaque "#13ff09" -trim alpha_cropped_${i}; done.
The resulting frames will work perfectly with customtransition.sh
(Figure 10).
Shortcomings
Be aware that I wrote customtransition.sh
for mainly educational purposes, as an example of how you imaginatively can use external tools to overcome the shortcomings of some Free Software video editors.
This means the script also has shortcomings of its own. For one, it only wipes from right to left. It would be trivial to implement transitions that ran left to right, but, for it to be a complete tool, you would probably also want top-to-bottom, bottom-to-top, center-to-edges, and edges-to-center … at the very least.
Additionally, if there is a "gap" in the body of the animation figure – imagine, for example, an actor throwing their hat in the air – the resulting animation frames will be wrong. The script uses floodfill
to fill in the color to the right of the actor. This means that color will flow through a gap to the left, making the whole background opaque and unusable for what you want.
That said, you can download the script [5] and try to improve it to meet your needs. Hopefully, this article will have given you enough clues on how to do that, so get creative!
Acknowledgments
The clips used in this tutorial are taken from Agent 327 [6] and Cosmos Laundromat [7], two of the great movies produced by the Blender Institute.
Infos
- "Creating custom transitions with FFmpeg" by Paul Brown, Linux Magazine issue 209, April 2018: http://www.linux-magazine.com/Issues/2018/209/Gobbling-Up
- Kdenlive: https://kdenlive.org/en/
- XOR binary logic operation: https://en.wikipedia.org/wiki/Exclusive_or
- ImageMagick: https://www.imagemagick.org/
- Download: https://gitlab.com/customcommandlinevideoediting/customtransitions
- Agent 327: https://cloud.blender.org/p/agent-327/
- Cosmos Laundromat: https://cloud.blender.org/p/cosmos-laundromat/
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
KDE Plasma 5.27 Beta is Ready for Testing
The latest beta iteration of the KDE Plasma desktop is now available and includes some important additions and fixes.
-
Netrunner OS 23 Is Now Available
The latest version of this Linux distribution is now based on Debian Bullseye and is ready for installation and finally hits the KDE 5.20 branch of the desktop.
-
New Linux Distribution Built for Gamers
With a Gnome desktop that offers different layouts and a custom kernel, PikaOS is a great option for gamers of all types.
-
System76 Beefs Up Popular Pangolin Laptop
The darling of open-source-powered laptops and desktops will soon drop a new AMD Ryzen 7-powered version of their popular Pangolin laptop.
-
Nobara Project Is a Modified Version of Fedora with User-Friendly Fixes
If you're looking for a version of Fedora that includes third-party and proprietary packages, look no further than the Nobara Project.
-
Gnome 44 Now Has a Release Date
Gnome 44 will be officially released on March 22, 2023.
-
Nitrux 2.6 Available with Kernel 6.1 and a Major Change
The developers of Nitrux have officially released version 2.6 of their Linux distribution with plenty of new features to excite users.
-
Vanilla OS Initial Release Is Now Available
A stock GNOME experience with on-demand immutability finally sees its first production release.
-
Critical Linux Vulnerability Found to Impact SMB Servers
A Linux vulnerability with a CVSS score of 10 has been found to affect SMB servers and can lead to remote code execution.
-
Linux Mint 21.1 Now Available with Plenty of Look and Feel Changes
Vera has arrived and although it is still using kernel 5.15, there are plenty of improvements sure to please everyone.