[PR #13053] [CLOSED] Set -copytb 1 in ffmpeg when creating an HLS stream, to fix "non-monotonic DTS" time breakage when remuxing. #13277

Closed
opened 2025-12-22 09:46:11 +01:00 by backuprepo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/13053
Author: @tsuereth
Created: 11/17/2024
Status: Closed

Base: masterHead: hls-ffmpeg-copytb


📝 Commits (3)

  • d0fb477 Set -copytb 1 which "is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate."
  • b12f354 Merge branch 'master' into hls-ffmpeg-copytb
  • 62e1c57 Use config ExperimentalFfmpegSetCopytb to set ffmpeg's -copytb option (default -1, matching the ffmpeg default).

📊 Changes

2 files changed (+6 additions, -1 deletions)

View changed files

📝 Jellyfin.Api/Controllers/DynamicHlsController.cs (+4 -1)
📝 MediaBrowser.Model/Configuration/ServerConfiguration.cs (+2 -0)

📄 Description

Set -copytb 1 which "is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate."

Does this adversely affect non-copy (transcode) streams? ... is an excellent question. :) In my limited testing, I don't think it does, though admittedly I don't have a ton of domain knowledge or relevant testing material.

Changes
This change simply adds -copytb 1 to ffmpeg's command-line arguments when creating an HLS stream. As ffmpeg documentation mentions: https://ffmpeg.org/ffmpeg.html

-copytb mode
Specify how to set the encoder timebase when stream copying. mode is an integer numeric value, and can assume one of the following values:

1
Use the demuxer timebase.

The time base is copied to the output encoder from the corresponding input demuxer. This is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate.

0
Use the decoder timebase.

The time base is copied to the output encoder from the corresponding input decoder.

-1
Try to make the choice automatically, in order to generate a sane output.

Default value is -1.

Like the doc says, when a source video has "non monotonically increasing timestamps," this setting appears necessary to ensure that a remux operation outputs frames with the source's intended timings.

Otherwise an HLS remux stream will adjust those non-monotonic timestamps, and produce a video which appears to miss or skip frames. This results in warnings logged by ffmpeg such as:

[vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: -1001, current: -1001; changing to -1000. This may result in incorrect timestamps in the output file.
[vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 2002, current: 2002; changing to 2003. This may result in incorrect timestamps in the output file.
[vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 6006, current: 6006; changing to 6007. This may result in incorrect timestamps in the output file.
[vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 9009, current: 9009; changing to 9010. This may result in incorrect timestamps in the output file.
[vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 13013, current: 13013; changing to 13014. This may result in incorrect timestamps in the output file.
...

Issues


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jellyfin/jellyfin/pull/13053 **Author:** [@tsuereth](https://github.com/tsuereth) **Created:** 11/17/2024 **Status:** ❌ Closed **Base:** `master` ← **Head:** `hls-ffmpeg-copytb` --- ### 📝 Commits (3) - [`d0fb477`](https://github.com/jellyfin/jellyfin/commit/d0fb4778fa771e65c9259ba4d78ace439fbdd9a4) Set `-copytb 1` which "is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate." - [`b12f354`](https://github.com/jellyfin/jellyfin/commit/b12f3540aa469882d3e0d304301c8689db6f32d4) Merge branch 'master' into hls-ffmpeg-copytb - [`62e1c57`](https://github.com/jellyfin/jellyfin/commit/62e1c57bce111f636d96605310e09d736eddc5cd) Use config `ExperimentalFfmpegSetCopytb` to set ffmpeg's `-copytb` option (default -1, matching the ffmpeg default). ### 📊 Changes **2 files changed** (+6 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `Jellyfin.Api/Controllers/DynamicHlsController.cs` (+4 -1) 📝 `MediaBrowser.Model/Configuration/ServerConfiguration.cs` (+2 -0) </details> ### 📄 Description Set `-copytb 1` which "is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate." **Does this adversely affect non-copy (transcode) streams?** ... is an excellent question. :) In my limited testing, I don't think it does, though admittedly I don't have a ton of domain knowledge or relevant testing material. **Changes** This change simply adds `-copytb 1` to ffmpeg's command-line arguments when creating an HLS stream. As ffmpeg documentation mentions: https://ffmpeg.org/ffmpeg.html > -copytb mode Specify how to set the encoder timebase when stream copying. mode is an integer numeric value, and can assume one of the following values: > 1 Use the demuxer timebase. > The time base is copied to the output encoder from the corresponding input demuxer. This is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate. > 0 Use the decoder timebase. > The time base is copied to the output encoder from the corresponding input decoder. > -1 Try to make the choice automatically, in order to generate a sane output. > Default value is -1. Like the doc says, when a source video has "non monotonically increasing timestamps," this setting appears necessary to ensure that a remux operation outputs frames with the source's intended timings. Otherwise an HLS remux stream will adjust those non-monotonic timestamps, and produce a video which appears to miss or skip frames. This results in warnings logged by ffmpeg such as: > [vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: -1001, current: -1001; changing to -1000. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 2002, current: 2002; changing to 2003. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 6006, current: 6006; changing to 6007. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 9009, current: 9009; changing to 9010. This may result in incorrect timestamps in the output file. [vost#0:0/copy @ 0x56517bc84400] Non-monotonic DTS; previous: 13013, current: 13013; changing to 13014. This may result in incorrect timestamps in the output file. ... **Issues** * https://github.com/jellyfin/jellyfin/issues/13052 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
backuprepo 2025-12-22 09:46:11 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/jellyfin#13277
No description provided.