-
Notifications
You must be signed in to change notification settings - Fork 74
Rename getKeyFrameIndexForPts into getKeyFrameIdentifier
#1076
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28bc995
Rename getKeyFrameIndexForPts into getKeyFrameIdentifier
NicolasHug 4d40573
Merge branch 'main' of github.com:pytorch/torchcodec into aefljnaef
NicolasHug a0f5ebc
Merge branch 'main' of github.com:pytorch/torchcodec into aefljnaef
NicolasHug 7cca5e4
more stuff
NicolasHug fc2142d
more stuff
NicolasHug 4485fbb
empty
NicolasHug f88a7ba
empty
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1092,13 +1092,6 @@ bool SingleStreamDecoder::canWeAvoidSeeking() const { | |
| // Returns true if we can avoid seeking in the AVFormatContext based on | ||
| // heuristics that rely on the target cursor_ and the last decoded frame. | ||
| // Seeking is expensive, so we try to avoid it when possible. | ||
| // Note that this function itself isn't always that cheap to call: in | ||
| // particular the calls to getKeyFrameIndexForPts below in approximate mode | ||
| // are sometimes slow. | ||
| // TODO we should understand why (is it because it reads the file?) and | ||
| // potentially optimize it. E.g. we may not want to ever seek, or even *check* | ||
| // if we need to seek in some cases, like if we're going to decode 80% of the | ||
| // frames anyway. | ||
| const StreamInfo& streamInfo = streamInfos_.at(activeStreamIndex_); | ||
| if (streamInfo.avMediaType == AVMEDIA_TYPE_AUDIO) { | ||
| // For audio, we only need to seek if a backwards seek was requested | ||
|
|
@@ -1145,10 +1138,10 @@ bool SingleStreamDecoder::canWeAvoidSeeking() const { | |
| // I P P P I P P P I P P I P | ||
| // x j y | ||
| // (2) is only more efficient than (1) if there is an I frame between x and y. | ||
| int lastKeyFrameIndex = getKeyFrameIndexForPts(lastDecodedAvFramePts_); | ||
| int targetKeyFrameIndex = getKeyFrameIndexForPts(cursor_); | ||
| return lastKeyFrameIndex >= 0 && targetKeyFrameIndex >= 0 && | ||
| lastKeyFrameIndex == targetKeyFrameIndex; | ||
| int lastKeyFrame = getKeyFrameIdentifier(lastDecodedAvFramePts_); | ||
| int targetKeyFrame = getKeyFrameIdentifier(cursor_); | ||
| return lastKeyFrame >= 0 && targetKeyFrame >= 0 && | ||
| lastKeyFrame == targetKeyFrame; | ||
| } | ||
|
|
||
| // This method looks at currentPts and desiredPts and seeks in the | ||
|
|
@@ -1365,7 +1358,19 @@ torch::Tensor SingleStreamDecoder::maybePermuteHWC2CHW( | |
| // PTS <-> INDEX CONVERSIONS | ||
| // -------------------------------------------------------------------------- | ||
|
|
||
| int SingleStreamDecoder::getKeyFrameIndexForPts(int64_t pts) const { | ||
| int SingleStreamDecoder::getKeyFrameIdentifier(int64_t pts) const { | ||
| // This function "identifies" a key frame for a given pts value. | ||
| // We use the term "identifier" rather than "index" because the nature of the | ||
| // index that is returned depends on various factors: | ||
| // - If seek_mode is exact, we return the index of the key frame in the | ||
| // scanned key-frame vector (streamInfo.keyFrames). So the returned value is | ||
| // in [0, num_key_frames). | ||
| // - If seek_mode is approximate, we use av_index_search_timestamp() which | ||
| // may return a value in [0, num_key_frames) like for mkv, but also a value | ||
| // in [0, num_frames) like for mp4. It really depends on the container. | ||
| // | ||
| // The range of the "identifier" doesn't matter that much, for now we only | ||
| // use it to uniquely identify a key frame in canWeAvoidSeeking(). | ||
|
Contributor
Author
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 can confirm the above on some test videos with 2 key frames. |
||
| const StreamInfo& streamInfo = streamInfos_.at(activeStreamIndex_); | ||
| if (streamInfo.keyFrames.empty()) { | ||
| return av_index_search_timestamp( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Drive-by, my previous comment above is incorrect:
getKeyFrameIndexForPts()in approximate mode is not slow. But it's not accurate (it doesn't return what we want it to return), so it's still the cause for the slowness. See #1077 for more details.