Kdenlive: Adding Meta Data and Cover Art to Rendered Files

In a previous blog post I wrote about rendering MP4 video including meta data in Kdenlive. This is very convenient, as you keep the meta data (such as title, author, copyright) in the best place: in your Kdenlive project. Unfortunately, the underlying ffmpeg handles only some, but not all (usable) of the iTunes-compatible meta data elements. Even worse, ffmpeg cannot add cover art. Time for another attempt: a Kdenlive post-rendering script...

Note: updated links to reference project kdenlive-post-render-script on GitHub.

Unfortunately, Kdenlive at this time has no dedicated means to run further tasks or programs after rendering of a video has finished. But luckily, there's still a more generic mechanism that Kdenlive supports: KDE notifications.

A Post-Rendering Action in Kdenlive

The idea to start from is this: Kdenlive triggers a notification after having finished rendering of a project. Here, notification doesn't exactly refer to the pop-up notification you may see on your desktop. Instead, this refers to a generic KDE mechanism called notifications, where KDE programs can define and trigger their own events. Such as the rendering finished notification in case of Kdenlive. That's what we would like to reuse...

Luckily, the KDE mechanism for notifications does not only desktop popup messages. It also supports running a command, or in other terms: running a program, or a shell script. So we would simply run a shell script that looks for meta data and cover art, and then adds them to the freshly rendered video file.

There is a slight catch though. So, how do we tell our script where our rendered video file and the meta data are? The first part is actually quite simple so solve: a quick search reveals a forum post describing the available options for passing information from a notification to the command to be run. Any %s in one of the command's parameters will be replaced with the notification text. And the notification text contains the full path and name of the rendered file. Phew, we lucky bastards!

But for the second part, the location of our meta data, we're out of luck. The command to be run is configured only once for all projects, so we can't set it up for each project individually. And unfortuntely, KDE notifications have no means to pass further, application-specific parameters either. So we're now out of luck and we need to come up with some trick that tries to locate the required meta data and cover art some way or another.

But let us first set up a script that gets run everytime Kdenlive finishes rendering a video file.

Running a script to add meta data after finishing rendering.

Note: There's an ugly bug in the Configure Notifications dialog. Whenever you reopen the dialog after you have configured a run command using %s, it will be wrongly sanitized as %25s. The same happens after clicking on Apply. However, %25s won't be replaced with the rendering message anymore, so the script will fail. You'll need to change back %25s back into %s each time you change the command or its options.
  1. Download the post-render-script.sh script file and place it into some suitable place, such as, for instance, the main folder of your Kdenlive projects (like ~/kdenlive). Make sure to make it executable.
  2. In Kdenlive, go to Settings > Configure Notifications.
  3. Select the line with the title Rendering finished.
  4. Check Run command.
  5. Select the post-render-script.sh that you've downloaded in the first step.
  6. Add "%s" to the command, in quotes, and with a space after the script file name and before the first quote.
  7. If you have your Kdenlive projects and/or meta data stored in a place different from ~/kdenlive, then please add your main folder containing Kdenlive projects as a second argument. For instance: ~/Videos/kdenlive.
  8. Click OK.
That's it for the KDE/Kdenlive notification part.

Installing AtomicParsley and Notify-Send

The post-render script needs some help from two applications:
  • AtomicParsley for adding meta data and cover art to MP4 files, and
  • notify-send to show a popup notification after either adding meta data or in case of certain errors.
I recommend installing a more recent version of AtomicParsley, as the original repository on SourceForge seems to be dead. On (x)Ubuntu, I had good results with Jon Davies' ppa.

On (x)Ubuntu installations, you may install the required packages as follows:
$sudo add-apt-repository ppa:jon-hedgerows/get-iplayer
$sudo apt-get update
$sudo apt-get install atomicparsley libnotify-bin

Adding Meta Data and Cover Art to Your Projects

With our script installed and its automatic trigger configured, we can now turn to the real meat: how to add iTunes-compatible meta data and a cover art image to your rendered video files.

Create a new meta data file for one of your Kdenlive rendered video files. Say, you have an Kdenlive project that renders to a MP4 file named foo.mp4.

Now, create a meta data text file called foo.meta and place it in a suitable place where our post-rendering script will find it. This should be somewhere in or below the folder that you wired up in step 7 when configuring how to run the script. The contents of foo.meta consists of key=value lines. For instance:
title=My Great Video
description=Yada, yada, yada!
The various allowed keys can be found when running AtomicParsley directly from the command line in a terminal window.

If you want to add cover art, then you need either a PNG or JPEG image file. It needs to be placed in the same place where your meta data file is, and its name must end in -cover before the suffix. In our case, this will be foo-cover.jpeg, foo-cover.jpg, or foo-cover.png.

The image dimensions can vary. For (home) movies your image may use a 2:3 portrait format, such as 1000×1500 pixels. For TV shows, the image can be square, with 600×600 pixels being the preferred dimension (in the iTunes universe) at this time.

    Post-Rendering Scripture Mechanics

    Usually, you should not need to edit the post-rendering script in order to immediately use it. The only customization that might be necessary is the main folder to start searching from for meta data files, and this information is specified through the notification configuration.

    The post-render script works basically as follows:
    1. It takes the filename of the rendered file as reported by Kdenlive and strips of the path. For instance, our newly rendered could be foo.mp4 (without the path).
    2. Next, the script tries to find a text file containing the meta data (such as title, author, copyright, description, et cetera). It therefore looks for a text file named foo.meta, starting from a directory specified as the second argument to the rendering script. We'll come shortly to how such a meta data file looks like.
    3. In addition, the script checks if there is a cover art image file in the same place where it found foo.meta. This image file needs to have the same file name, but with -cover tacked on, such as foo-cover.jpeg, foo-cover.jpg, or foo-cover.png. As you may notice, supported image formats are JPEG and PNG.
    4. When at least the meta data text file has been found, the script calls AtomicParsley with the necessary information in order to add the iTunes meta data and cover art image to your freshly rendered video file.