Skip to content

Expose the Duration Field for Frames#1880

Merged
WyattBlue merged 1 commit intoPyAV-Org:mainfrom
Queuecumber:main
Apr 30, 2025
Merged

Expose the Duration Field for Frames#1880
WyattBlue merged 1 commit intoPyAV-Org:mainfrom
Queuecumber:main

Conversation

@Queuecumber
Copy link
Contributor

@Queuecumber Queuecumber commented Apr 29, 2025

This PR exposes the duration field on frame objects as the time that a given frame should be displayed for in time_base units.

This can simplify certain decode loops which are searching for specific frames in time, e.g.:

for frame in container.decode(video=0):
  if (frame.pts <= target_time_pts <= frame.pts + frame.duration):
    break # Found it

In this example the frame might not occur at the target pts so we need to use duration to check if the frame would be onscreen at the target time.

Currently this can be done by computing an average frame duration using the average frame rate (which is error prone) or trying to synchronize to the packets duration field.

@Queuecumber Queuecumber force-pushed the main branch 2 times, most recently from 70695f5 to 9f86191 Compare April 29, 2025 23:33
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
@WyattBlue WyattBlue merged commit d00c98d into PyAV-Org:main Apr 30, 2025
5 checks passed
@Queuecumber
Copy link
Contributor Author

Thanks for the fast turnaround on this

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.

2 participants