Skip to content

Fix audio-video sync issue in DASH MP4 muxer#13369

Open
Gautam-aman wants to merge 4 commits intoTeamNewPipe:devfrom
Gautam-aman:fix/audio-video-sync
Open

Fix audio-video sync issue in DASH MP4 muxer#13369
Gautam-aman wants to merge 4 commits intoTeamNewPipe:devfrom
Gautam-aman:fix/audio-video-sync

Conversation

@Gautam-aman
Copy link
Copy Markdown

@Gautam-aman Gautam-aman commented Mar 22, 2026

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

Fix audio-video synchronization issue in DASH MP4 muxing.

Audio and video tracks extracted from DASH streams may have different starting
composition timestamps (PTS), which previously caused desynchronization.

This PR normalizes timestamps by:

  • Capturing initial PTS for each track
  • Computing a global minimum PTS once all tracks are initialized
  • Introducing a stable per-track base timestamp (basePts)
  • Preventing mid-stream timestamp reference switching
  • Adjusting CTTS offset calculation accordingly

This ensures both tracks share a consistent timeline during muxing.


APK testing

Tested using locally built APK.

  • Verified on multiple YouTube videos (480p, 720p)
  • Checked using frame-by-frame playback in VLC
  • No audio-video desync observed

Due diligence

  • I read the contribution guidelines.
  • The proposed changes follow the AI policy.
  • I tested the changes using an emulator or a physical device.

Issue

Fixes #12640

@github-actions github-actions bot added the size/medium PRs with less than 250 changed lines label Mar 22, 2026
@absurdlylongusername absurdlylongusername added template missing The bug/feature template is missing (e.g. the used app does not support issue templates) template ignored The user didn't follow the template/instructions (or removed them) labels Mar 22, 2026
@absurdlylongusername
Copy link
Copy Markdown
Member

Please do not remove the default PR template. Restore it and fill it in properly

@Gautam-aman
Copy link
Copy Markdown
Author

Thanks! I’ve restored the PR template and filled it properly.

@absurdlylongusername absurdlylongusername removed template missing The bug/feature template is missing (e.g. the used app does not support issue templates) template ignored The user didn't follow the template/instructions (or removed them) labels Mar 22, 2026
@absurdlylongusername
Copy link
Copy Markdown
Member

Could you please give a detailed explanation of how your solution works and how it fixes the problem, as well as provide clear instructions of how to test that the solution fixes the problem?

Either the code must be self-explanatory, or it must be explained elsewhere in documentation such as in this PR description: but right now there is neither.

I don't know what PTS is or how this works, and it would be best for everyone to remove all assumed knowledge and have things be clear as possible and easily understood.

@TobiGr TobiGr added bug Issue is related to a bug youtube Service, https://www.youtube.com/ downloader Issue is related to the downloader labels Mar 30, 2026
Copy link
Copy Markdown
Contributor

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. I tried to run your changes, but they do not seem to fix the problem. I used the video from #12640 and still got a desync / no audio at 32:52. Please explain in detail how your fix works.

Comment on lines +360 to +370
final boolean allSet;
{
boolean temp = true;
for (int k = 0; k < readers.length; k++) {
if (!firstPtsSet[k]) {
temp = false;
break;
}
}
allSet = temp;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your code here. Why do you introduce a temp var? Can't you set allSet = false directly? This should be equal to you code but is easier to understand:

Suggested change
final boolean allSet;
{
boolean temp = true;
for (int k = 0; k < readers.length; k++) {
if (!firstPtsSet[k]) {
temp = false;
break;
}
}
allSet = temp;
}
boolean allSet = true;
for (int k = 0; allSet && k < readers.length; k++) {
if (!firstPtsSet[k]) {
allSet = false;
}
}

Comment on lines +169 to +170
final boolean[] minPtsComputedArr = new boolean[]{false};
final long[] minPtsArr = new long[]{0};
Copy link
Copy Markdown
Contributor

@TobiGr TobiGr Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two vars arrays? They both only hold one value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue is related to a bug downloader Issue is related to the downloader size/medium PRs with less than 250 changed lines youtube Service, https://www.youtube.com/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[YouTube] Out of sync audio and video in download (muxing issue)

3 participants