Bug 500850

Summary: Motion tracker crash when size too small
Product: [Applications] kdenlive Reporter: mittenworx
Component: Video Effects & TransitionsAssignee: Jean-Baptiste Mardelle <jb>
Status: CONFIRMED ---    
Severity: crash CC: fritzibaby, poracoppa75
Priority: NOR Keywords: triaged
Version First Reported In: 24.12.2   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description mittenworx 2025-02-28 02:39:37 UTC
SUMMARY
When editing keyframes on the motion tracker plugin, if the user accidentally resizes the affected area to zero height or less, kdenlive crashes

STEPS TO REPRODUCE
1. Add a video clip to the project
2. Add the motion tracker video effect
3. Set shape width to 0 and blur type to gaussian
4. Analyze to apply
5. Edit one of the resulting keyframes by dragging the bottom handle in the preview window up until it meets the top handle

OBSERVED RESULT
kdenlive instantly crashes

EXPECTED RESULT
The bottom handle should stop moving once it reaches the top handle, without crashing

SOFTWARE/OS VERSIONS
Windows: 10 version 22H2 build 19045.5371

ADDITIONAL INFORMATION
Comment 1 Jean-Baptiste Mardelle 2025-03-14 13:09:04 UTC
Git commit 9dfaef69810f0fb754eda437f40a4743d354e11c by Jean-Baptiste Mardelle.
Committed on 14/03/2025 at 13:08.
Pushed by mardelle into branch 'release/25.04'.

Motion tracker: create keyframes with smooth_natural type instead of the deprecated smooth that caused cusps and could lead to empty area causing crashes

M  +3    -0    src/jobs/filtertask.cpp

https://invent.kde.org/multimedia/kdenlive/-/commit/9dfaef69810f0fb754eda437f40a4743d354e11c
Comment 2 Jean-Baptiste Mardelle 2025-03-14 14:29:29 UTC
Thanks for your report. After some testing, I could reproduce a crash, here is what happens:
When resizing the rectangle in the monitor window, you can create very small rectangles, but not smaller than 1x1 pixel. This does not cause a crash. However the problem is that the motion tracker created keyframes using the deprecated smooth type, which could cause overflow.
This means that when moving from a large rectangle to a very small one and back again to a large one, we could be in a situation there the rectangle is null, which caused the crash. I fixed this by enforcing keyframes to use the more recent smooth_natural type which doesn't have this issue.

It would be great if you could test the latest development build of Kdenlive that contains my change to confirm if it fixes the issue for you.
The installer can be found here:
https://cdn.kde.org/ci-builds/multimedia/kdenlive/master/windows/
Comment 3 mittenworx 2025-03-15 21:04:56 UTC
(In reply to Jean-Baptiste Mardelle from comment #2)
> Thanks for your report. After some testing, I could reproduce a crash, here
> is what happens:
> When resizing the rectangle in the monitor window, you can create very small
> rectangles, but not smaller than 1x1 pixel. This does not cause a crash.
> However the problem is that the motion tracker created keyframes using the
> deprecated smooth type, which could cause overflow.
> This means that when moving from a large rectangle to a very small one and
> back again to a large one, we could be in a situation there the rectangle is
> null, which caused the crash. I fixed this by enforcing keyframes to use the
> more recent smooth_natural type which doesn't have this issue.
> 
> It would be great if you could test the latest development build of Kdenlive
> that contains my change to confirm if it fixes the issue for you.
> The installer can be found here:
> https://cdn.kde.org/ci-builds/multimedia/kdenlive/master/windows/

Hello,

Thank you for taking a look into this. I downloaded development build 9861 dated 2025-03-15 17:49 from the link you provided and tested it. I was able to reproduce the bug one time immediately upon trying. I had some more free time today than when I originally submitted the bug so I attempted to get a development environment set up so that I could provide a crash log. While Craft was downloading I decided to open the development build again and play with it some more. The second time I played with it for at least five minutes, moving many keyframes around and resizing them in all sorts of different ways and this time I could not get the bug to reproduce. I will try again once I have the dev environment fully set up and I'm able to build kdenlive with gdb.
Comment 4 editwithmyfeet 2025-03-28 09:33:02 UTC
Windows 11 24H2
kdenlive master 9948 

If this can help,

I created a project with motion tracking effect with blur applied. -Was happy with the result. -saved my project.
On project re-opening attempts, kdenlive consistently crashed. 

I found a temporary fix (if it can provide any insight)

I edited my project file MyProject.kdenlive in a text editor 

Found the tag
<property name="blur_type">1</property>		which i presume is value for "Gaussian Blur"

I passed it to
<property name="blur_type">4</property> 	which again i presume stands for "None"

I then saved my project file in the text editor

I was able to re-open this project file in kdenlive.

When using the motion tracking effect in kdenlive, pass the blur type to none before saving your project.

Could this this bug being related to adding blur instead of rectangle null pattern size?
Comment 5 Jean-Baptiste Mardelle 2025-03-28 09:54:02 UTC
Could you paste here the full xml for the motion tracking effect in your project file ? should be something like: 

 <filter id="filter10">
   <property name="shape_width">0</property>
   <property name="steps">5</property>
   <property name="algo">KCF</property>
   <property name="mlt_service">opencv.tracker</property>
   <property name="kdenlive_id">opencv.tracker</property>
   <property name="results">00:00:00.000=834 374 331 444;00:00:00.200~=830 382 331 444;00:00:00.400~=827 406 331 444;00:00:00.600~=820 426 331 444;00:00:00.800~=833 418 331 444;00:00:01.000~=852 382 331 444;00:00:01.200~=865 507 5 3;00:00:01.400~=832 360 331 444;00:00:01.600~=831 368 331 444;00:00:01.800~=832 376 331 444;00:00:02.000~=837 374 331 444;00:00:02.200~=868 366 331 444;00:00:02.400~=875 368 331 444;00:00:02.600~=864 374 331 444;00:00:02.800~=847 376 331 444;00:00:03.000~=848 374 331 444</property>
   <property name="shape">0</property>
   <property name="shape_color">0xff0000ff</property>
   <property name="blur">20</property>
   <property name="blur_type">1</property>
   <property name="modelsfolder"/>
   <property name="rect">50</property>
   <property name="kdenlive:collapsed">0</property>
  </filter>
Comment 6 Jean-Baptiste Mardelle 2025-03-29 11:15:19 UTC
Thanks for sending me the xml. I can confirm it crashes when blur is enabled and size = 1 pixel. Working on a fix