Skip to content

Conversation

@Noarkhh
Copy link
Contributor

@Noarkhh Noarkhh commented Dec 3, 2025

No description provided.

@Noarkhh Noarkhh self-assigned this Dec 3, 2025
@Noarkhh Noarkhh added this to Smackore Dec 3, 2025
@Noarkhh Noarkhh moved this to In Progress in Smackore Dec 3, 2025
@Noarkhh Noarkhh added the no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md label Dec 3, 2025
@Noarkhh Noarkhh changed the base branch from master to dynamic-pads-guide December 3, 2025 18:12
@Noarkhh Noarkhh force-pushed the dynamic-pads-guide branch 2 times, most recently from 9841fae to b4539b0 Compare December 19, 2025 12:46
Base automatically changed from dynamic-pads-guide to master December 19, 2025 12:51
@Noarkhh Noarkhh marked this pull request as ready for review January 7, 2026 10:59
@Noarkhh Noarkhh requested a review from mat-hek as a code owner January 7, 2026 10:59
@Noarkhh Noarkhh moved this from In Progress to In Review in Smackore Jan 7, 2026
@Noarkhh Noarkhh requested review from FelonEkonom and varsill January 7, 2026 10:59
Copy link
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

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

Sounds great. I'm missing some summary/guidelines, that would emphasise that:

  • DTS should always be monotonic, while PTS for video with B-frames can be non-monotonic
  • Filters should always forward timestamps
  • If a filter doesn't use timestamps, it should forward them, but not rely on them being set
  • Sources should attach timestamps to buffers whenever they're known
  • Whenever possible, elements should rely on timestamps instead of framerate or audio duration calculated from the stream
  • If an element queues buffers in its state (or uses a library that does so), it should make sure that the timestamps for the output buffers are the same as for the corresponding input buffers
  • You should make sure that calculations on timestamps don't introduce an accumulating error. Prefer using rationals (Ratio library) to floats.
  • Elements should generate deterministic output timestamps for better testability
  • If an element transforms N input buffers into M output buffers, each of the output buffers should have either:
    • the timestamp of the first of the input buffers (even if only a part of it was used to construct the output buffers)
    • more precise timestamps, if it's possible to calculate them
  • Timestamps are harder than they seem and are the source of many bugs, including:
    • Audio/video desynchronization
    • Stream hanging (due to waiting indefinitely to process/play a buffer because of a wrong timestamp)
    • Stream stalls (e.g. due to processing a real-time stream slightly faster than real time)
    • Memory leaks (e.g. due to processing a real-time stream slightly slower than real time and indefinite buffering)
    • Video flickering (due to incorrect handling of B-frames)
    • Audio cracking
      Therefore, the operations on timestamps should be given a lot of care and be well-tested

@@ -0,0 +1,100 @@
# Timestamps

In a nutshell, timestamps determine when a given event occurred in time. For
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In a nutshell, timestamps determine when a given event occurred in time. For
In a nutshell, timestamps determine when a given event occurred (or should occur) in time. For

send them over as fast as possible, which is not something we want. We want the receiver
to get the stream in realtime, so that they can display it as it comes.

## Decoding Time Stamps
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## Decoding Time Stamps
## Decode Time Stamps (DTS)

@Noarkhh Noarkhh requested a review from mat-hek January 8, 2026 16:42
[Realtimer](https://hexdocs.pm/membrane_realtimer_plugin/Membrane.Realtimer.html)
is an element from
[membrane_realtimer_plugin](https://hex.pm/packages/membrane_realtimer_plugin).
It takes in a stream and limits its flow according to its PTSs. For example, if
Copy link
Member

Choose a reason for hiding this comment

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

Not really, it will take dts || pts

should make sure that the timestamps for the output buffers are the same as for
the corresponding input buffers.
* You should ensure that calculations on timestamps don't introduce an
accumulating error. Prefer using rationals (Ratio library) to floats.
Copy link
Member

Choose a reason for hiding this comment

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

maybe some link to ratio?

to create a term representing three seconds, we call `Membrane.Time.seconds(3)`.
* To read the amount of time represented, we can use `Membrane.Time.as_<unit>/2`
functions. For example, to get an amount of milliseconds represented by a time,
we call `Membrane.Time.as_milliseconds(some_time)`
Copy link
Member

Choose a reason for hiding this comment

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

Membrane.Time.as_milliseconds/1? It would generate a link to as_milliseconds docs, I guess

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

Labels

no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Identify and add missing explanations for Membrane concepts and use cases

4 participants