-
Notifications
You must be signed in to change notification settings - Fork 376
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
Prevent repeating frame indices #1265
Conversation
df6be33
to
4c45957
Compare
4c45957
to
83e20c3
Compare
I would like there to be performance benchmarks ran on I'm curious why you choose to extract the logic of |
I'm very doubtful about this PR, do we even know why we have this As far as I can tell:
Unless it's actually used somewhere, another approach would be to remove the attribute completely. |
Performance Benchmarks@WyattBlue I ran some rudimentary performance benchmarks using the following code:
I did 3 runs on each branch and got the following average durations:
If you were referring to more sophisticated benchmarking, I'll need some help to get started. Function vs InlineThe only reason I made a function was to make it slightly more organized. If you prefer that I change to inline, that's perfectly fine with me. |
AVFrame@jlaine I looked through AVFrame Struct Reference and found This issue seems to also conclude that Docs |
Thanks for the documentation pointers. It seems a bit weird that this member is mentioned in examples, but there isn't event a docstring clarifying the fact it's an index generated by pyav, and that it has no influence on encoding. If the point is purely to have a running index, what is gained over doing: for (index, frame) in enumerate(container.decode(video=0)):
... |
@jlaine Yeah, that's a good point. However, since It seems these problems arise from the fact that How about this solution:
The problem is If
Ideally we would be able to get a frame's index from ffmpeg, but I can't find a way to do it at the moment. I think this new solution solves many problems:
|
I agree with jlaine. We should deprecate and remove |
Fix for Issue #1158.
Problem
stream.thread_type.FRAME
threading causes an incorrect series of repeating frame indices at the end of most videos. This is because a list of frames is returned byCodecContext._send_packet_and_recv
.frame.index
corresponds to the most recent frame received from the decoder. Therefore all frames in the list are assigned the same index as the final frame in the list.Solution
I solved this issue by detecting whenever multiple frames are returned and then correcting the
frame.index
based on the frame's position in the list.Other changes
AVCodecContext::frame_number
is deprecated. I switched toAVCodecContext::frame_num
.EDIT: The deprecation was issued in ffmpeg 6.0, so I reverted back to using
AVCodecContext::frame_number
.Testing
The test iterations may be overkill, but it only increased the test run time from 6 seconds to 6.5 seconds on my machine.
Future considerations
It is important to note that
frame.index
is affected byCodecContext.skip_frame
. Skipped frames will not increment the frame index. I don't know if this is intended or desired behavior. Perhaps we should consider two different frame properties.1: A property for the number of frames returned by the decoder (this is the current behavior).
2: A property for the frame index relative to the total number of frames in the video. I assume this can be determined by a timestamp?