Skip to content

Season of KDE'24 - Blog 1

Updated: at 02:53 PM

Adding Multi-Format Rendering to Kdenlive

sdfsdfdsfdsfsdf Source:

About Me

I am Ajay Chauhan (IRC:, currently in my second year of undergraduate studies in Computer Science & Engineering. I’ll be working on adding multi-format rendering to Kdenlive for my Season of KDE project. This post describes my journey with KDE and why I submitted this project for the Season of KDE.

My introduction to KDE and Kdenlive

I was first introduced to KDE when I was distrohopping, starting with Ubuntu GNOME, then Arch, and finally settling on KDE Neon so that I could experience KDE’s latest features. Although it was a bit buggy at times, I enjoyed using the KDE Plasma so much that I’ve stuck with it for over two years now.

I also used the Qt framework to write GUI applications in C++ for school projects in the past. The Season of KDE will also allow me to get better acquainted with KDE development

What is Kdenlive?

Kdenlive is a free and open-source video editing software that is based on the MLT Framework. Kdenlive is an acronym for KDE Non-Linear Video Editor. It works on GNU/Linux, Windows, BSD and MacOS.
Whenever I’ve needed to edit videos, Kdenlive has always been my go-to video editor. I’ve used it to edit presentations for college and small projects.

I’ll be working on adding Multi-format rendering (horizontal/vertical/square) to Kdenlive for my Season of KDE project. By adding support for rendering in horizontal, portrait, and square formats at export, videos can be rendered in different aspect ratios for different social media platforms and use cases easily.

My mentors for the project are Julius Künzel and Jean-Baptiste Mardelle.

The key tasks of my project are :

This will allow users to render videos tailored for different popular platforms for use cases like social media stories, square videos for Instragram post etc.

Work done so far

At first, I did the math on how to get the aspect ratio right. The core of the implementation is a calculateCropParameters function that calculates the correct cropping, given the source and destination aspect ratios. It determines whether the source video needs to be cropped on the sides for a wider aspect or on the top and bottom for a taller aspect ratio.

calculateCropParameters(sourceAspectRatio, targetAspectRatio, ...) {
  if (sourceAspectRatio differs from target) {
    if (source wider than target) {
       // crop sides
    } else {
       // crop top and bottom
  } else {
    // no crop needed

For this the first step in this process was to extract the properties of the source video: its width, height, and Display Aspect Ratio (DAR).

int sourceWidth = pCore->getCurrentProfile()->width();
int sourceHeight = pCore->getCurrentProfile()->height();
double sourceAspectRatio = pCore->getCurrentProfile()->dar();

The pCore->getCurrentProfile() function plays a main role here, providing access to the video’s current profile settings, including the DAR. The DAR gives the width-to-height ratio of the video as displayed.

Setting Crop Parameters

After calculating the necessary crop dimensions, the final step was to apply these adjustments to the video. This was done by setting up a crop filter with the calculated parameters from calculateCropParameters.

std::unique_ptr<Mlt::Filter> cropFilter = std::make_unique<Mlt::Filter>(pCore->getProjectProfile(), "crop");
cropFilter->set("left", leftOffset);
cropFilter->set("right", sourceWidth - cropWidth - leftOffset);
cropFilter->set("top", topOffset);
cropFilter->set("bottom", sourceHeight - cropHeight - topOffset);

Demo video of work till now:

Merge Request: Implement Multi-format Rendering↗

The main challenges faced in setting up a new profile were configuring the producer and consumer xmlConsumer2() to render video in the new aspect ratio profile when generating an XML playlist. Thanks to the mentor, who helped a lot with this task.

What’s next?

In the upcoming weeks, I plan to add a GUI, modify the user interface to allow users to select the desired aspect ratio during export. And also ensure that I don’t leave any bit and that it doesn’t give any kind of error with the different aspect ratio of the source video that the user provides.