Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg: Rescale DTS better during FPS passthrough #416

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

j0sh
Copy link
Collaborator

@j0sh j0sh commented Aug 10, 2024

This mostly ensures that non-B frames have the same dts/pts.

The PTS/DTS from the encoder can be "squashed" a bit during rescaling back to the source timebase if it is used directly, due to the lower resolution of the encoder timebase. We avoid this problem with the PTS in in FPS passthrough mode by reusing the source pts, but only rescale the encoder-provided DTS back to the source timebase for some semblance of timestamp consistency. Because the DTS values are squashed, they can differ from the PTS even with non-B frames.

The DTS values are still monotonic, so the exact numbers are not really important. However, some tools use dts == pts as a heuristic to check for B-frames ... so help them out to avoid spurious B-frame detections.

To fix the DTS/PTS mismatch, take the difference between the encoder-provided dts/pts, rescale that difference back to the source time base, and re-calculate the dts using the source pts.

Also see #405

This mostly ensures that non-B frames have the same dts/pts.

The PTS/DTS from the encoder can be "squashed" a bit during rescaling
back to the source timebase if it is used directly, due to the lower
resolution of the encoder timebase. We avoid this problem with the
PTS in in FPS passthrough mode by reusing the source pts, but only
rescale the encoder-provided DTS back to the source timebase for some
semblance of timestamp consistency. Because the DTS values are
squashed, they can differ from the PTS even with non-B frames.

The DTS values are still monotonic, so the exact numbers are not really
important. However, some tools use `dts == pts` as a heuristic to check
for B-frames ... so help them out to avoid spurious B-frame detections.

To fix the DTS/PTS mismatch, take the difference between the
encoder-provided dts/pts, rescale that difference back to the source
time base, and re-calculate the dts using the source pts.

Also see #405
Copy link

@Thulinma Thulinma left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@thomshutt thomshutt merged commit b5181eb into master Aug 12, 2024
3 checks passed
@thomshutt thomshutt deleted the ja/dts-difference branch August 12, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants