-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix issues with seeking in some H.264 videos on native & web #8111
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
01be0f8
remove minimum timestamp again
Wumpf 0d4a157
update re_mp4
Wumpf a8fe2d2
fix warnings
Wumpf dbcb237
fixup test_latest_sample_index_at_presentation_timestamp
Wumpf 74e651e
Merge branch 'main' into andreas/mp4-update
emilk c40676b
Use if-false instead of comments
emilk 391a379
Destruct SamplesStatistics
emilk 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 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -75,19 +75,6 @@ pub struct VideoData { | |
/// Meta informationa about the video samples. | ||
#[derive(Clone, Debug)] | ||
pub struct SamplesStatistics { | ||
/// The smallest presentation timestamp observed in this video. | ||
/// | ||
/// This is typically 0, but in the presence of B-frames, it may be non-zero. | ||
/// In fact, many formats don't require this to be zero, but video players typically | ||
/// normalize the shown time to start at zero. | ||
/// Note that timestamps in the [`Sample`]s are *not* automatically adjusted with this value. | ||
// This is roughly equivalent to FFmpeg's internal `min_corrected_pts` | ||
// https://github.com/FFmpeg/FFmpeg/blob/4047b887fc44b110bccb1da09bcb79d6e454b88b/libavformat/isom.h#L202 | ||
// (unlike us, this handles a bunch more edge cases but it fulfills the same role) | ||
// To learn more about this I recommend reading the patch that introduced this in FFmpeg: | ||
// https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/#12592 | ||
pub minimum_presentation_timestamp: Time, | ||
|
||
/// Whether all decode timestamps are equal to presentation timestamps. | ||
/// | ||
/// If true, the video typically has no B-frames as those require frame reordering. | ||
|
@@ -103,11 +90,6 @@ impl SamplesStatistics { | |
pub fn new(samples: &[Sample]) -> Self { | ||
re_tracing::profile_function!(); | ||
|
||
let minimum_presentation_timestamp = samples | ||
.iter() | ||
.map(|s| s.presentation_timestamp) | ||
.min() | ||
.unwrap_or_default(); | ||
let dts_always_equal_pts = samples | ||
.iter() | ||
.all(|s| s.decode_timestamp == s.presentation_timestamp); | ||
|
@@ -128,7 +110,6 @@ impl SamplesStatistics { | |
}); | ||
|
||
Self { | ||
minimum_presentation_timestamp, | ||
dts_always_equal_pts, | ||
has_sample_highest_pts_so_far, | ||
} | ||
|
@@ -301,8 +282,6 @@ impl VideoData { | |
/// Determines the video timestamps of all frames inside a video, returning raw time values. | ||
/// | ||
/// Returned timestamps are in nanoseconds since start and are guaranteed to be monotonically increasing. | ||
/// These are *not* necessarily the same as the presentation timestamps, as the returned timestamps are | ||
/// normalized respect to the start of the video, see [`SamplesStatistics::minimum_presentation_timestamp`]. | ||
pub fn frame_timestamps_ns(&self) -> impl Iterator<Item = i64> + '_ { | ||
// Segments are guaranteed to be sorted among each other, but within a segment, | ||
// presentation timestamps may not be sorted since this is sorted by decode timestamps. | ||
|
@@ -311,12 +290,7 @@ impl VideoData { | |
.iter() | ||
.map(|sample| sample.presentation_timestamp) | ||
.sorted() | ||
.map(|pts| { | ||
pts.into_nanos_since_start( | ||
self.timescale, | ||
self.samples_statistics.minimum_presentation_timestamp, | ||
) | ||
}) | ||
.map(|pts| pts.into_nanos(self.timescale)) | ||
}) | ||
} | ||
|
||
|
@@ -638,16 +612,16 @@ mod tests { | |
fn test_latest_sample_index_at_presentation_timestamp() { | ||
// This is a snippet of real world data! | ||
let pts = [ | ||
512, 1536, 1024, 768, 1280, 2560, 2048, 1792, 2304, 3584, 3072, 2816, 3328, 4608, 4096, | ||
3840, 4352, 5376, 4864, 5120, 6400, 5888, 5632, 6144, 7424, 6912, 6656, 7168, 8448, | ||
7936, 7680, 8192, 9472, 8960, 8704, 9216, 10496, 9984, 9728, 10240, 11520, 11008, | ||
10752, 11264, 12544, 12032, 11776, 12288, 13568, 13056, | ||
0, 1024, 512, 256, 768, 2048, 1536, 1280, 1792, 3072, 2560, 2304, 2816, 4096, 3584, | ||
3328, 3840, 4864, 4352, 4608, 5888, 5376, 5120, 5632, 6912, 6400, 6144, 6656, 7936, | ||
7424, 7168, 7680, 8960, 8448, 8192, 8704, 9984, 9472, 9216, 9728, 11008, 10496, 10240, | ||
10752, 12032, 11520, 11264, 11776, 13056, 12544, | ||
]; | ||
let dts = [ | ||
0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, | ||
3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, | ||
7424, 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10752, | ||
11008, 11264, 11520, 11776, 12032, 12288, 12544, | ||
-512, -256, 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, | ||
3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, | ||
6912, 7168, 7424, 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, | ||
10496, 10752, 11008, 11264, 11520, 11776, 12032, | ||
]; | ||
|
||
// Checking our basic assumptions about this data: | ||
|
@@ -671,7 +645,6 @@ mod tests { | |
.collect::<Vec<_>>(); | ||
|
||
let sample_statistics = SamplesStatistics::new(&samples); | ||
assert_eq!(sample_statistics.minimum_presentation_timestamp, Time(512)); | ||
assert!(!sample_statistics.dts_always_equal_pts); | ||
|
||
// Test queries on the samples. | ||
|
@@ -704,30 +677,30 @@ mod tests { | |
// A few hardcoded cases - both for illustrative purposes and to make sure the generic tests above are correct. | ||
|
||
// Querying before the first sample. | ||
assert_eq!(None, query_pts(Time(0))); | ||
assert_eq!(None, query_pts(Time(123))); | ||
assert_eq!(None, query_pts(Time(-1))); | ||
assert_eq!(None, query_pts(Time(-123))); | ||
|
||
// Querying for the first sample | ||
assert_eq!(Some(0), query_pts(Time(512))); | ||
assert_eq!(Some(0), query_pts(Time(513))); | ||
assert_eq!(Some(0), query_pts(Time(600))); | ||
assert_eq!(Some(0), query_pts(Time(767))); | ||
assert_eq!(Some(0), query_pts(Time(0))); | ||
assert_eq!(Some(0), query_pts(Time(1))); | ||
assert_eq!(Some(0), query_pts(Time(88))); | ||
assert_eq!(Some(0), query_pts(Time(255))); | ||
|
||
// The next sample is a jump in index! | ||
assert_eq!(Some(3), query_pts(Time(768))); | ||
assert_eq!(Some(3), query_pts(Time(769))); | ||
assert_eq!(Some(3), query_pts(Time(800))); | ||
assert_eq!(Some(3), query_pts(Time(1023))); | ||
assert_eq!(Some(3), query_pts(Time(256))); | ||
assert_eq!(Some(3), query_pts(Time(257))); | ||
assert_eq!(Some(3), query_pts(Time(400))); | ||
assert_eq!(Some(3), query_pts(Time(511))); | ||
|
||
// And the one after that should jump back again. | ||
assert_eq!(Some(2), query_pts(Time(1024))); | ||
assert_eq!(Some(2), query_pts(Time(1025))); | ||
assert_eq!(Some(2), query_pts(Time(1100))); | ||
assert_eq!(Some(2), query_pts(Time(1279))); | ||
assert_eq!(Some(2), query_pts(Time(512))); | ||
assert_eq!(Some(2), query_pts(Time(513))); | ||
assert_eq!(Some(2), query_pts(Time(600))); | ||
assert_eq!(Some(2), query_pts(Time(767))); | ||
|
||
// And another one! | ||
assert_eq!(Some(4), query_pts(Time(1280))); | ||
assert_eq!(Some(4), query_pts(Time(1281))); | ||
assert_eq!(Some(4), query_pts(Time(768))); | ||
assert_eq!(Some(4), query_pts(Time(1023))); | ||
|
||
// Test way outside of the range. | ||
// (this is not the last element in the list since that one doesn't have the highest PTS) | ||
|
This file contains 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
This file contains 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.
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.
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.
If you use
if false {
instead the code won't code-rot