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
Figure 9: You can use basically anything you want to create a customized transition, including footage of some random dude walking across the screen.

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).

Figure 10: The final result.

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!

Figure 7: Mark the Import image sequence checkbox to import frames as a clip.

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.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Slideshows with Kdenlive

    Kdenlive plays to its strengths when editing larger video projects and also helps users create appealing slideshows with impressive effects.

  • Tutorials – Natron

    Natron allows you to create eye-catching effects and combine different video clips in surprising ways, letting you build up your clips like a pro.

  • Gobbling Up

    Most video editors supply you with a generic catalog of transitions, usually in the shape of tired wipes and fades. But what if you wanted something a little more special? FFmpeg to the rescue.

  • Tutorials – Natron

    Natron gives you the power to apply sophisticated effects to your videos, but its node-based interface can be a bit confusing. This tutorial will help you get a grasp on the basics.

  • Video Editor Roundup

    In a comparison test, we checked out nine free video editing programs: Cinelerra, Flowblade, Kdenlive, Kino, Lightworks, LiVES, OpenShot, Pitivi, and Shotcut.

comments powered by Disqus
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

News