Bug 419461 - Audio out of sync in rendered output
Summary: Audio out of sync in rendered output
Status: RESOLVED FIXED
Alias: None
Product: kdenlive
Classification: Applications
Component: Video Display & Export (show other bugs)
Version: git-master
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Jean-Baptiste Mardelle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-31 17:21 UTC by alriddoch
Modified: 2020-09-13 09:29 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 20.04.2
fritzibaby: Brainstorm+


Attachments
Project which can reproduce this issue (438.87 KB, application/x-kdenlive)
2020-04-12 11:19 UTC, alriddoch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alriddoch 2020-03-31 17:21:26 UTC
SUMMARY

When rendering a project, the resulting output has audio which gradually gets ahead of the video output. The overall sync deviation was about 10 seconds over a 14 minute video. The render phase reports the following error for every frame for the last 10 seconds of the render:

[consumer avformat] error with audio encode: -541478725 (frame 21094)

The last ~10 seconds of the rendered video are completely silent, as the audio has already reached the end of the data.

I have reproduced this error with kdenlive built from git master, and with kdenlive-20.07.70-689e351-x86_64.appimage

STEPS TO REPRODUCE
1. Load any project into kdenlive
2. Render the project to output video
3. 

OBSERVED RESULT

The audio drifts gradually out of sync in the output, about 1% ahead of the rendered video.

EXPECTED RESULT

The audio should be in-sync with the video.


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Fedora 31
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 5.61.0
Qt Version: 5.12.4

ADDITIONAL INFORMATION
My project profile is 1080p, 25fps, and I am rendering to mp4 using the standard Format settings.
Comment 1 alriddoch 2020-03-31 18:27:54 UTC
It looks as though this may be a mlt/melt problem, as the skew does not occur if I export a render script, and render it using mlt 6.18.0. Rendering with an older mlt is not a solution, as that version is missing rubberband support.


(Exporting a render script, and rendering with mlt git master does reproduce the bug).
Comment 2 alriddoch 2020-03-31 21:10:10 UTC
I've narrowed it down to a change in mlt git:

2020-02-12 05:00:29 87997b59c0090ae28633a1266716ed6c841e9976

This is the merge of bmatherly/pitch_compensate which I believe adds the capability which kdenlive used for its pitch compensation option. This makes some sense, as my test project makes heavy use of clips with increased speed, and pitch compensation enabled.

Can anyone in kdenlive advise on the best way to proceed? I'm not familiar enough with mlt to create a repro directly in melt. It looks to me as though this is going to impact any kdenlive project which uses pitch compensation.
Comment 3 alriddoch 2020-03-31 22:10:13 UTC
Another verification that warp_pitch is to blame:

I manually flipped every instance of warp_pitch to 0 in the project, and the audio sync problem has gone. The total drift is consistent with a single frame of extra audio being added for each clip which has warp_pitch enabled.
Comment 4 alriddoch 2020-04-02 22:03:06 UTC
This is proving very difficult to reproduce independently. My current project still repros the issue reliably, but I have not been able to create a new simpler project that reproduces the issue.

Obviously this means my original report that it can be reproduced with any project is incorrect, but I don't yet have a consistent criteria for reproducing the bug.
Comment 5 alriddoch 2020-04-12 11:13:58 UTC
I am now able to consistently reproduce this problem with a relatively simple repro project.

The project is a single one minute video with two pieces of wood being snapped together (like an improvised clapper board) at roughly ten second intervals.
The whole video is added to the timeline, then divided up into about 60 small clips of irregular size. Each clip has the speed set to 200%, and has "Pitch compensation" enabled.

In the rendered output, by the end of the video the audio is over two seconds ahead of the video.

I can reproduce this in 20.04-rc2 and git master.
Comment 6 alriddoch 2020-04-12 11:19:46 UTC
Created attachment 127466 [details]
Project which can reproduce this issue

The video file referenced by this project is way over the file size limit, but I can provide it shared to an email address, or uploaded to anywhere you specify on request.
Comment 7 alriddoch 2020-04-12 11:20:20 UTC
I've attached the repro project, and can provide a copy of the referenced video file (too large to attach here) on request.
Comment 8 emohr 2020-04-12 12:45:53 UTC
Thank you very much for this indeep analysis. Out of sync audio with rendering is an issue we have.
Comment 9 Jean-Baptiste Mardelle 2020-04-23 20:40:44 UTC
Hello and thanks a lot for your detailed report. Could you share the project clip for this project so that I can investigate ? You can send me a mail at my @kdenlive.org address for the file link.
Comment 10 alriddoch 2020-04-23 21:12:06 UTC
I've sent the file to your address via WeTransfer.

Many thanks for taking a look. Do let me know if there is anything else I can do to help.
Comment 11 Jean-Baptiste Mardelle 2020-04-24 16:08:21 UTC
I can confirm it's an interesting issue affecting the MLT audio pipeline.
I have opened an issue with a simplified project on MLT's bugtracker:
https://github.com/mltframework/mlt/issues/551
Comment 12 emohr 2020-09-12 18:31:17 UTC
Thank you very much for helping solving this issue on MLT. Please let me know if we could close this issue.
Comment 13 alriddoch 2020-09-12 19:25:25 UTC
This is fixed as far as I am concerned.
Comment 14 emohr 2020-09-13 09:29:59 UTC
Again many thanks for your contribution to find the root cause of this de-sync issue. I could close many bugs due to this fix.