Bug 501280 - Audio thumbnail wrong for second audio track in mkv with two audio tracks
Summary: Audio thumbnail wrong for second audio track in mkv with two audio tracks
Status: RESOLVED FIXED
Alias: None
Product: kdenlive
Classification: Applications
Component: Audio Effects & Transitions (show other bugs)
Version: 24.12.2
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: Jean-Baptiste Mardelle
URL:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2025-03-09 22:41 UTC by gdorn_kde
Modified: 2025-04-01 09:09 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 25.04.0
Sentry Crash Report:


Attachments
Clip exhibiting issue (2.66 MB, video/x-matroska)
2025-03-31 19:56 UTC, gdorn_kde
Details
Screenshot showing issue (15.83 KB, image/png)
2025-03-31 20:00 UTC, gdorn_kde
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gdorn_kde 2025-03-09 22:41:53 UTC
***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports

Please remove this comment after reading and before submitting - thanks!
***

SUMMARY


STEPS TO REPRODUCE
1.  Create a video file with multiple audio tracks.  I did this with MKVToolNix, but also gpu-screen-recorder with multiple audio tracks does the same.
2.  Import into project, wait for thumbnail to be calculated.  Match the project to the video file (just in case).
3.  Drag the video, or a clip segment from it, to the timeline.  

OBSERVED RESULT
The first audio track's thumbnail is right, but the second one is wrong.  Offset by a few seconds? It's hard to say for sure.
I can swap the two audio tracks, again using MKVToolNix, and the pattern repeats - the first audio track in the file has the correct thumbnail, the second one does not.

The audio itself is unaffected; it is how I noticed the thumbnail was wrong in the first place.

EXPECTED RESULT
Both audio track thumbnails match the audio contained within them.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Manjaro.  I'm running the 24.12.2 AppImage version of kdenlive, though.
KDE Plasma Version: n/a
KDE Frameworks Version: n/a
Qt Version: n/a
Comment 1 gdorn_kde 2025-03-09 22:44:19 UTC
Well, I'd fix the description field, but there's no edit button.  Feel free to dress this one up.
Comment 2 emohr 2025-03-11 09:31:38 UTC
Thank you for reporting. We have a complete new audio wave form calculation in the upcoming version 25.04. If you don't mind have a look on the latest master build and check if the issue is still happen. https://cdn.kde.org/ci-builds/multimedia/kdenlive/master/linux/

Please keep in mind that the master is for testing only. Any feedback is welcome.
Comment 3 Jean-Baptiste Mardelle 2025-03-27 07:40:55 UTC
Can you please confirm if the issue still happens with development builds ? Or provide a sample clip reproducing the issue. Without further feedback, we will close this bug.
Comment 4 gdorn_kde 2025-03-31 18:53:15 UTC
Ah, I did not realize that the bug tracking system was not set up to ingest email.  I did extensive testing and attempted to send this on March 11:

Yes, I just tested on Kdenlive Version 25.07.70 and found the same result - the thumbnail for the second audio track is incorrect.

Master is showing an additional bug, though - at some zoom levels, the second half of the thumbnail is simply blank.  Sometimes when previewing it'll populate the second half, and then if I change zoom levels the thumbnail changes somewhat randomly, though never representing what is actually being played.
I re-tested the same file on 24.12.2 and it does not show this behavior, just the thumbnail being wrong, so whatever change is in master may actually be worse at this.

More details regarding the original bug:
- It doesn't appear to be codec-related.  I thought might be caused by the Opus codec, but I have some MKVs containing two Opus tracks that produce the bug, and some that do not.  It may relate to length; I'm still looking for a file shorter than a half hour that exhibits the bug.
- The thumbnail appears to be shifted left by 7-8 seconds, at least in this one test case.  If I compare the audio track in audacity, both it and kdenlive play the sound at the right time, but kdenlive's thumbnail looks like the sound should have play about 7-8 seconds earlier.  When the master version doesn't exhibit the additional instability bug, that offset is consistent across versions.
Comment 5 Jean-Baptiste Mardelle 2025-03-31 19:21:31 UTC
Could you check if the 2 audio streams have the same length ? This command should print the length of the first audio stream:

ffmpeg -i input.mkv -c copy -map 0:a:0 -f null - 2>&1 | tail -3 | grep -oP "(?<=time=).+?\s"

And for the second stream:

ffmpeg -i input.mp4 -c copy -map 0:a:1 -f null - 2>&1 | tail -3 | grep -oP "(?<=time=).+?\s"
Comment 6 gdorn_kde 2025-03-31 19:56:54 UTC
Created attachment 179894 [details]
Clip exhibiting issue

Short clip showing issue.  Track 1 is fine, but thumbnail for track 2 shows audio several seconds before the actual audio content.
Comment 7 gdorn_kde 2025-03-31 19:58:25 UTC
Added a clip showing the issue.  In the full file, the lengths are 02:13:07:72 for track 1 and 02:13:07:82 for track 2.  In the shorter clip, the lengths are 00:00:14.99 and 00:00:15.01.  Neither seems sufficiently different to account for 7 seconds of offset.
Comment 8 gdorn_kde 2025-03-31 20:00:02 UTC
Created attachment 179895 [details]
Screenshot showing issue

In this screenshot, the second audio track shows an audio waveform of a brief voice clip; it suggests the voice is present roughly halfway through the clip, but the voice does not actually begin until the last couple seconds.
Comment 9 gdorn_kde 2025-03-31 20:01:01 UTC
Comment on attachment 179895 [details]
Screenshot showing issue

Ignore the filename in the screenshot; I had to transcode to get under the 4MB limit, but the new file also looks the same.
Comment 10 Jean-Baptiste Mardelle 2025-04-01 08:47:48 UTC
Thanks for providing the file. I can confirm that the clip thumbnail in timeline for the second stream has an offset, but the audio preview for the two streams in the Clip monitor is still correct. Will work on it.
Comment 11 Jean-Baptiste Mardelle 2025-04-01 09:09:18 UTC
Git commit 4fc03d21abfae214c6497e2c347fc8a39a83683a by Jean-Baptiste Mardelle.
Committed on 01/04/2025 at 09:09.
Pushed by mardelle into branch 'release/25.04'.

Fix timeline audio thumbnails for clips with multiple streams and different channel count
FIXED-IN: 25.04.0

M  +2    -2    src/bin/projectclip.cpp
M  +2    -2    src/bin/projectclip.h
M  +4    -1    src/lib/audio/audioStreamInfo.cpp
M  +1    -1    src/lib/audio/audioStreamInfo.h
M  +1    -1    src/timeline2/model/clipmodel.cpp

https://invent.kde.org/multimedia/kdenlive/-/commit/4fc03d21abfae214c6497e2c347fc8a39a83683a