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
![](/var/linux_magazin/storage/images/issues/2018/213/tutorials-kdenlive-and-imagemagick/figure-9/730943-1-eng-US/Figure-9_large.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
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.