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
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.