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

frame index of video frame #33

Closed
mkassner opened this issue Jul 9, 2014 · 10 comments
Closed

frame index of video frame #33

mkassner opened this issue Jul 9, 2014 · 10 comments
Labels

Comments

@mkassner
Copy link
Contributor

mkassner commented Jul 9, 2014

Since frame.pts is often only by coincidence equal to frame index in video stream (and will ultimately fail with non constant frame rates), I was hoping for frame.index to represent the frame index in the steam.

However, it appears that frame index == encoded frame count on frame creation. This mean that after a seek the index become -at least the way I understand it- false.

Any ideas on how to fix that?

@mikeboers
Copy link
Member

Unfortunately, I don't think that sort of information is available from FFmpeg/Libav, as it may not be a common thing for codecs to encode into individual frames/packets.

@mkassner
Copy link
Contributor Author

ok, that makes sense. I just thought it might be possible because of a few members in the AVframe struct:

int     coded_picture_number
    #picture number in bitstream order 

int     display_picture_number
    #picture number in display order 

@mikeboers
Copy link
Member

They look promising, but (IIRC) they are set in essentially the same manner as PyAV's Frame.index, and just won't work across a seek. =[

On Jul 12, 2014, at 1:17 AM, mkassner notifications@github.com wrote:

ok, that makes sense. I just thought it might be possible because of a few members in the AVframe struct:

int coded_picture_number
#picture number in bitstream order

int display_picture_number
#picture number in display order

Reply to this email directly or view it on GitHub.

@mkassner
Copy link
Contributor Author

Alright. Thanks for the clarification!

@mikeboers
Copy link
Member

Seems like the documentation should be improved, at the least.

@markreidvfx
Copy link
Contributor

If the video is constant frame rate, the frame number should be pts_seconds / frame_rate. That might be good enough for most codecs, assuming the file is encoded correctly, doesn't drop or repeat frames. The only way to do it 100% accurately as far as I understand is to decode every frame and count and then make a pts seek table.
That's what this project does, https://github.com/lbrandy/ffmpeg-fas

@mkassner
Copy link
Contributor Author

I was hoping for frame indices of variable frame rate videos, otherwise frame index is always just pts/framerate like you said. I was hoping seek tables to already be present in the container. Building one ourselves is not hard so I will go with that!

@mikeboers
Copy link
Member

I'm going to leave this open as a documentation issue.

@mikeboers mikeboers reopened this Jul 13, 2014
@mikeboers mikeboers added bug and removed bug labels Jul 13, 2014
@funkybob
Copy link

In my own code, after much painful and tedious research :) I have the following:

'''
        PTS (Presentation Time Stamp), which indicates when this frame should
        be shown, is expressed according to stream.time_base.

        We can compare the PTS to frame numbers if we scale by:
            (stream.average_rate / stream.time_base)
'''
pts_scale = video_stream.average_rate * video_stream.time_base

frame_pts = int(frame_index / pts_scale)

I'm not certain how portable this is, as we only use MP4 video streams.

@jlaine
Copy link
Member

jlaine commented Nov 7, 2018

I'm going to close this issue, as the following time-related attributes are properly documented nowadays:

  • dts
  • pts
  • time_base

@jlaine jlaine closed this as completed Nov 7, 2018
keunhong added a commit to keunhong/pims that referenced this issue May 8, 2019
See PyAV-Org/PyAV#33

It seems like the index property is unreliable. I've encountered cases
where a packet will have two frames with the same "index" property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants