-
Notifications
You must be signed in to change notification settings - Fork 64
Rough implementation of getting key frame indices #484
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
Changes from all commits
0219f92
1bcfaa5
736401c
121a9fd
ef644f9
1670dc6
09ada7c
d80e795
1c06f1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -831,6 +831,49 @@ def test_get_frames_by_pts_in_range_fails(self, device, seek_mode): | |
with pytest.raises(ValueError, match="Invalid stop seconds"): | ||
frame = decoder.get_frames_played_in_range(0, 23) # noqa | ||
|
||
@pytest.mark.parametrize("device", cpu_and_cuda()) | ||
def test_get_key_frame_indices(self, device): | ||
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode="exact") | ||
key_frame_indices = decoder._get_key_frame_indices() | ||
|
||
# The key frame indices were generated from the following command: | ||
# $ ffprobe -v error -hide_banner -select_streams v:1 -show_frames -of csv test/resources/nasa_13013.mp4 | grep -n ",I," | cut -d ':' -f 1 > key_frames.txt | ||
# What it's doing: | ||
# 1. Calling ffprobe on the second video stream, which is absolute stream index 3. | ||
# 2. Showing all frames for that stream. | ||
# 3. Using grep to find the "I" frames, which are the key frames. We also get the line | ||
# number, which is also the count of the rames. | ||
# 4. Using cut to extract just the count for the frame. | ||
# Finally, because the above produces a count, which is index + 1, we subtract | ||
# one from all values manually to arrive at the values below. | ||
Comment on lines
+846
to
+848
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose you meant the same thing, but my understanding is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I meant the same thing. I can try to clarify. |
||
# TODO: decide if/how we want to incorporate key frame indices into the utils | ||
# framework. | ||
nasa_reference_key_frame_indices = torch.tensor([0, 240]) | ||
|
||
torch.testing.assert_close( | ||
key_frame_indices, nasa_reference_key_frame_indices, atol=0, rtol=0 | ||
) | ||
|
||
decoder = VideoDecoder(AV1_VIDEO.path, device=device, seek_mode="exact") | ||
key_frame_indices = decoder._get_key_frame_indices() | ||
|
||
# $ ffprobe -v error -hide_banner -select_streams v:0 -show_frames -of csv test/resources/av1_video.mkv | grep -n ",I," | cut -d ':' -f 1 > key_frames.txt | ||
av1_reference_key_frame_indices = torch.tensor([0]) | ||
|
||
torch.testing.assert_close( | ||
key_frame_indices, av1_reference_key_frame_indices, atol=0, rtol=0 | ||
) | ||
|
||
decoder = VideoDecoder(H265_VIDEO.path, device=device, seek_mode="exact") | ||
key_frame_indices = decoder._get_key_frame_indices() | ||
|
||
# ffprobe -v error -hide_banner -select_streams v:0 -show_frames -of csv test/resources/h265_video.mp4 | grep -n ",I," | cut -d ':' -f 1 > key_frames.txt | ||
h265_reference_key_frame_indices = torch.tensor([0, 2, 4, 6, 8]) | ||
|
||
torch.testing.assert_close( | ||
key_frame_indices, h265_reference_key_frame_indices, atol=0, rtol=0 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the line-noise of a shell command on a single line so that it's easier to copy-paste. It does make it harder to read, but making it easy to read means breaking it up over several lines, and then when you go to copy-paste, there's the
#
comment markers in there. Happy to change it to a better way.