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
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.
News
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.