[kdenlive] adjusting *.mkv format and/or codecs when rendring output streaming file

Recently I used kdenlive to edit some video files (hiding private data on video
using alpha shapes masks).

prior to running kdenlive:
the streaming mkv input file was split from a large streaming file using MKVToolNix

after running kdenlive:
attempting to merge back appended to end of the large streaming mkv file, getting an error
streams codecs are different cant merge.

what will be the best known and most simple approach to make the formats/codecs fit?


Difficult to say as MKV is just a container. Maybe convert the MKV clip in the project bin to a edit friendly format?

I don’t quite understand this.

Why was it split in the first place? And then, did you import to Kdenlive and edit there just the video stream?

Please elaborate …

hi berndmj
Why was it split in the first place?
When I started recording video advisory casts, the most available
free opensource tool available was OBS. by default it use *.mkv
format for video + audio recording. I try to preserve format -
as much as possible to prevent excessive learning effort with
multiple tools for video casts preparing.
at first some expert advised me to split the section I wish to edit
and edit it separately. by retrospective they are right there is a quality
deterioration in video stream after editing with kdenlive, some tiles
are shifted and/or turning green color at the video image. using small
section reduce damage to the wall cast.

did you import to Kdenlive and edit there just the video stream?

No I imported all the streams at the *.mkv file. some expert face
difficulty to synchronize audio when multiplexing video channels with
audio channels. there is a shift in audio timing , mismatch with video
timing. I avoid getting into this problem by simply edit all streams under
matrska (mkv) container, preserving synchronizations.

“100 experts can’t fetch a stone thrown to the well by one idiot”

Thanks for elaborating. This is what I understand from your posts:

  • You record a long session with OBS creating a big .mkv file
  • The original file is split into several pieces using MKVToolNix
  • You edit the various pieces in Kdenlive and render it as a .mkv file
  • You try to append the rendered .mkv files to the original (unedited but split) .mkv file

Frankly, I would have expected that behavior from the beginning. OBS may be using the MKV container but the encoding is a different topic. Kdenlive also uses the MKV container but the encoding of the edited pieces is also a different topic. One cannot expect that one can stitch together different pieces of video/audio that have the same wrapper but potentially different content without re-encoding (and even then it will most likely be visible where editing took place).

I suggest to load the entire OBS recording into Kdenlive, edit it there and then render the whole thing (perhaps overnight).

Thanks berndmj

as I experience using kdenlive it deteriorate video quality in presence
of alpha shapes (mask). I would expect inferior video quality to any
re-rendered video using alpha shapes (mask) in kdenlive.

For this reason (reduced video quality) I prefer doing as much as possible
in OBS and MKVToolNix, only section with specific privacy censoring needs
should face this reduced video quality.

I have consulted chatGPT got the advise to use lossless compression
on the sections with alpha shapes (mask) , it will inflate file size but maintain
reasonable quality. MKV is a very strong container when considering
multiplexing different compression rates in sections of video.

attached the talk with chatGPT… :wink:

how can I prevent deterioration of video streaming quality when apply alpha shapes (mask) effect of kdenlive video editing tool?

Preventing the deterioration of video streaming quality while applying alpha shapes (mask) effects in Kdenlive or any video editing tool requires some optimization techniques. Alpha shapes involve transparency or masking effects, which can be computationally intensive and affect video quality during playback or streaming. Here are some tips to help you maintain video quality:

    Use Appropriate Video Codec: Choose an efficient video codec for rendering/exporting your video. H.264 or H.265 (HEVC) are commonly used codecs that offer good compression and quality balance. Higher compression will reduce the file size, but keep in mind that excessive compression can lead to quality loss.

    Adjust Render Settings: When exporting your video, make sure to adjust the render settings appropriately. Set a reasonable bitrate and resolution that suits your needs. Higher bitrate and resolution will result in better quality, but it may also increase file size and streaming requirements.

    Hardware Acceleration: If your computer supports hardware acceleration for video encoding, enable it. Hardware acceleration utilizes your GPU (Graphics Processing Unit) to offload some of the video encoding tasks from the CPU, resulting in faster and more efficient rendering.

    Proxy Editing: For complex projects with many effects, consider using proxy editing. Proxy editing creates lower-resolution versions of your video clips for editing, which are easier to handle for your computer. When you're done editing, you can switch back to the full-resolution files for the final export.

    Optimize Effects: Experiment with different masks or alpha shapes and try to use the simplest effect that achieves your desired result. Complex masks or numerous overlapping effects can put a strain on your system and reduce video quality.

    Preview Quality: During editing, you can lower the preview quality to reduce the computational load on your computer. This allows for smoother real-time playback during editing, but it doesn't affect the final export quality.

    Render in Batches: If your project is long or contains many effects, consider rendering it in smaller batches. This can help reduce the risk of crashing or encountering errors during the rendering process.

    Monitor System Resources: Keep an eye on your computer's resource usage while editing and rendering. Close unnecessary background applications and ensure your computer has sufficient free memory and storage space.

    Update Software: Ensure you are using the latest version of Kdenlive and have updated drivers for your GPU. Newer software versions often come with performance improvements and bug fixes.

Remember that achieving the right balance between video quality and streaming performance may require some trial and error. Experiment with different settings and methods to find the best configuration for your specific project and hardware capabilities.
witch of the points is most effective improvement of quality?

Among the points listed, the most effective improvement for maintaining video streaming quality while applying alpha shapes (mask) effects in Kdenlive or any video editing tool would likely be:

    Use Appropriate Video Codec: Choosing the right video codec can significantly impact the quality of your video during streaming. H.264 or H.265 (HEVC) are widely used codecs known for their efficient compression and relatively high quality. They strike a good balance between file size and video fidelity, which is essential for streaming videos over the internet.

Using an appropriate video codec ensures that your video retains its quality while keeping the file size manageable for smooth streaming. It optimizes the balance between image clarity and bandwidth requirements, making it the most effective improvement to prevent deterioration of video streaming quality.

Of course, all the listed points are valuable, and the combination of multiple optimizations can further enhance the overall video quality and streaming performance. However, choosing the right video codec is the foundation for maintaining video quality during streaming. After that, you can implement other tips to further refine the streaming experience and optimize performance during editing and rendering.
way does video quality deteriorate on the first place ? can I force the application use exactly same encoding as input ? will it deteriorate anyway in presence of the alpha shapes mask?

Video quality can deteriorate due to various factors, and the application of alpha shapes (masks) can be one of the contributing factors. Here's why video quality might deteriorate:

    Lossy Compression: Many video codecs, such as H.264 or H.265, use lossy compression to reduce the file size. In lossy compression, some visual information is permanently removed from the video to achieve higher compression. While this results in smaller file sizes, it also leads to a loss of video quality compared to the original, uncompressed footage.

    Transparency Effects (Alpha Shapes): Applying alpha shapes or transparency effects involves using masking to show or hide certain parts of the video. This can introduce additional complexity to the video, especially if there are overlapping or intricate masks. Handling transparency in video codecs can be more computationally demanding, and this can impact the overall video quality during rendering or streaming.

    Repeated Encoding: If you edit and export a video multiple times, each re-encoding can introduce cumulative quality loss. Repeated encoding leads to a generation loss, where the video quality gradually degrades with each iteration.

    Bitrate and Resolution: Lowering the bitrate or resolution during encoding can reduce file sizes, but it also results in lower video quality. Insufficient bitrate may cause compression artifacts, blurriness, or blockiness in the video.

    Hardware Limitations: The performance of your computer's CPU and GPU can also affect the quality of video playback and rendering. If the hardware is not powerful enough to handle the video and effects smoothly, the video quality may suffer during playback.

Regarding using the same encoding as the input, it is possible to maintain the original encoding by using a lossless codec or by selecting a high-quality, low-compression setting for the output. However, this will result in larger file sizes, and it may not always be practical for streaming purposes.

Even if you try to maintain the same encoding as the input, the presence of alpha shapes (masks) can still impact video quality. The masks introduce additional complexity to the video, and depending on the complexity of the masks and the video codec used, there can be a loss of quality during rendering or streaming due to increased computational demands.

To mitigate the impact of alpha shapes on video quality, you can follow the optimization tips mentioned earlier, such as using hardware acceleration, adjusting render settings, and optimizing effects. These can help strike a balance between maintaining quality and efficient streaming performance. Additionally, testing different settings and codecs will help you find the best compromise between video quality and file size for your specific project.
yet it is too obscure answer, my encoding is H264 I use latest version in ubuntu and kdenlive, my computer is new with 3060 gpu. I use pass-threw so same encoding for output.  I fill like there is some simple config flow to improve the output video. can you direct me to some parameters and setting on kdenlive to achieve it?

Apologies for the earlier response. Given your setup with H.264 encoding and a powerful GPU, there are indeed some specific settings you can adjust in Kdenlive to improve the output video quality while applying alpha shapes (masks) effects. Here are some steps you can follow:

    Project Settings:
        Open your Kdenlive project and go to "Project" > "Project Settings."
        Under the "Video Profile" tab, make sure you have selected an appropriate H.264 profile. For example, you can choose "H.264 High Profile" or "H.264 Main Profile." Higher profiles generally offer better video quality.

    Render Settings:
        After finishing your editing, go to "Project" > "Render Project."
        In the "Render" dialog, choose the following settings:
            Format: Choose "File" and then "H.264."
            Quality: Select a high-quality preset or manually adjust the bitrate. Higher bitrates generally result in better quality but larger file sizes.
            Resolution: Choose the same resolution as your input video or the desired output resolution.
            Frame Rate: Select the same frame rate as your input video to avoid any unnecessary frame rate conversions.
            Check "Use maximum quality" and "Pass-through" options if available. These options can help maintain the original quality during rendering.

    Preview Scaling:
        To improve real-time playback performance during editing, you can lower the preview scaling. In the Kdenlive interface, adjust the preview scaling to 1/2 or 1/4 by clicking on the "Settings" icon on the top-right corner of the preview window.

    Use Proxy Editing (Optional):
        If your project is very complex and your system struggles with real-time playback, you can enable proxy editing. Kdenlive allows you to create lower-resolution proxy files for smoother editing. To enable proxy editing, go to "Settings" > "Configure Kdenlive" > "Playback" and set "Proxy clip resolution" to a lower value.

    Hardware Acceleration (NVIDIA NVENC):
        Since you have an NVIDIA GPU, you can enable hardware acceleration for rendering using the NVENC encoder. In the "Render" dialog, under the "Video" tab, select "NVIDIA NVENC" as the encoder if available.

    Avoid Excessive Overlapping Effects:
        Try to minimize the complexity of the alpha shapes (masks) you apply. Excessive overlapping effects can increase computational demands and impact video quality.

    Test Different Bitrates and Settings:
        You may need to experiment with different bitrate settings and other parameters to find the best balance between video quality and file size for your specific project.

Remember that achieving the best output quality depends on various factors, including the complexity of your project, the source footage, and the desired output settings. By following these steps and fine-tuning the settings, you should be able to improve the video quality while applying alpha shapes effects in Kdenlive.
I don't care about processing time, getting same quality like input justify even x10 time longer processing. I intend to share this video in podcast on an university. the quality is much important than effort to produce the video

If maintaining the same quality as the input is your top priority, regardless of processing time, you can use a lossless or visually lossless video codec for the output. This will ensure that the video quality remains as close to the original as possible without any additional compression artifacts.

One of the most popular lossless video codecs is H.264 Lossless. Here's how you can set up Kdenlive to use H.264 Lossless for your video:

    Project Settings:
        Open your Kdenlive project and go to "Project" > "Project Settings."
        Under the "Video Profile" tab, click on the "Custom" option to create a custom video profile.

    Custom Video Profile:
        In the "Custom Video Profile" dialog, give your profile a name (e.g., "Lossless H.264").
        For the "Video Codec," choose "H.264 Lossless."
        Set the desired resolution, frame rate, and any other video settings you want to keep consistent with the input video.

    Render Settings:
        After finishing your editing, go to "Project" > "Render Project."
        In the "Render" dialog, choose the following settings:
            Format: Choose "File" and then "Custom" to select your Lossless H.264 profile from the dropdown list.
            You can leave the "Quality" slider at the maximum (100%) for lossless output.
            Set the destination path and filename for the exported video.

    Render Video:
        Click the "Start" button to begin the rendering process.

Using the H.264 Lossless codec will preserve the video quality, but it will result in much larger file sizes compared to compressed formats like H.264 with lossy compression. Keep this in mind if you plan to share the video online or through other platforms with size limitations.

Since you mentioned that processing time is not a concern, using a lossless codec should meet your requirements for preserving video quality at the expense of larger file sizes. You can rest assured that the video will look identical to the input in terms of quality.
can I multiplex *.mkv container format video stream with lossless compression after a compressed section with same config for all other parameters using mkvtoolnix? the edited section is only 2  minutes wile the main video about one hour  (at the beginning of the file)?

Yes, you can multiplex a lossless compressed video stream with the same configuration as the rest of the video using MKVToolNix. MKVToolNix is a powerful tool for manipulating Matroska (MKV) container files, allowing you to combine multiple video, audio, and subtitle streams into a single MKV file.

If you have a long video with a compressed section at the beginning and a lossless compressed section for the edited part, you can follow these steps:

    Prepare the Compressed Video:
        Ensure that the beginning part of your video (about one hour) is already compressed with the desired configuration. If it's already in MKV format, you can skip this step.

    Compress the Edited Section:
        Use your preferred video encoding software to compress the edited section (about two minutes) using the lossless configuration you desire. Ensure that the resolution, frame rate, and other settings match the original video.

    Use MKVToolNix:
        Open MKVToolNix GUI (Graphical User Interface) or MKVToolNix command-line interface (CLI).
        Add the original compressed video (one-hour part) by clicking on "Add source files" or using the command-line option -o for the first video.

    Add the Edited, Lossless Compressed Video:
        Click on "Add source files" or use the command-line option -o to add the edited, lossless compressed video (two-minute part) to MKVToolNix.

    Select Tracks and Settings:
        In MKVToolNix GUI, you'll see the two video tracks listed.
        For each track, you can specify additional settings like language, title, and compression settings if required. Ensure that the settings for the lossless part match those of the original compressed part.

    Multiplex (Mux) the Tracks:
        After configuring the tracks, click on "Start multiplexing" in MKVToolNix GUI, or if you are using the CLI, execute the command to mux the tracks.

MKVToolNix will combine the two video tracks into a single MKV container file. The first part (one-hour compressed) and the second part (two-minute lossless compressed) will be seamlessly combined into one video file. The overall video quality should be preserved for the entire duration, with the lossless section maintaining its original quality.

Remember that combining videos with different settings or codecs might result in a larger file size due to the lossless part. Ensure that you have sufficient storage space to accommodate the resulting MKV file.

I would like to throw to the brainstorming ideas people a challenge to automatically perform
such split perform lossless rendering and re-merge under mkv container in kdenlive with any
effect/filter that is supposed to deteriorate the video quality… it must be possible, sure such automation will be requiered by all the video editing community.

I am curious to see whether this approach will allow you to append the rendered sections to the unedited parts. Frankly, I have my doubts because I think quality settings have no bearing on whether or not MKVToolNix can work with the two or more files. But I’ll stand corrected …

Please keep us posted.