Repository navigation
InputContainer.seek(backward=True, any_frame=False) overshoots #1982
Replies: 1 comment
|
Your units in the I tried a small synthetic 5-fps HEVC file with a 20-frame keyframe interval in PyAV 19.0.1. Its keyframe at presentation time 8.0 s had an earlier DTS, but seeking to 7.2 s returned the previous keyframe at 4.0 s. So I did not reproduce your exact overshoot; the file, demuxer index, encoder settings and versions may matter. A robust workaround is to verify the first decoded frame after seeking. If its presentation time is already beyond the target, seek farther back (ultimately to the beginning) and decode forward. Compare It would help to include your PyAV/FFmpeg versions and the key packets' |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am trying to get a specific frame index from a video as fast as possible. The strategy I follow is what the docs of
InputContainer.seeksuggest - I callInputContainer.seek(backward=True, any_frame=False)so that I get the closest previous keyframe and then decode forward sequentially to the desired frame. I am using the following codeI am testing this with a video with 5 FPS and keyframes at indices 0, 20, 40, 60. All frames from 0 to 35 work fine, but when I pass
frame_index=36, the first framecontainer.decode(stream)returns in the for loop after the call tocontainer.seekis the keyframe at index 40. If I instead seek withcontainer.seek(int(target_timestamp_sec * av.time_base), backward=True, any_frame=False), the error happens at index 19 and the keyframe returned is 20. The video is encoded with x265 andstream.time_base = 1 / 10240. The frames also have the expected time and pts:All reactions