Skip to content
Snippets Groups Projects
Verified Commit 65e7174d authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Avoid decoding packets with no relevant timestamps

parent 91e04057
No related branches found
No related tags found
No related merge requests found
...@@ -223,6 +223,10 @@ impl AVPacket { ...@@ -223,6 +223,10 @@ impl AVPacket {
unsafe { self.base.as_ref() }.unwrap_or_else(|| panic!("AVPacket base unexpectedly null")) unsafe { self.base.as_ref() }.unwrap_or_else(|| panic!("AVPacket base unexpectedly null"))
} }
pub fn duration(&self) -> i64 {
self.as_ref().duration
}
pub fn pts(&self) -> i64 { pub fn pts(&self) -> i64 {
self.as_ref().pts self.as_ref().pts
} }
......
...@@ -91,6 +91,23 @@ pub fn extract( ...@@ -91,6 +91,23 @@ pub fn extract(
while avformat_context.read_frame(&mut packet).is_ok() { while avformat_context.read_frame(&mut packet).is_ok() {
if packet.stream_index() == index { if packet.stream_index() == index {
let duration = media_time::MediaTime::from_rational(packet.duration(), &time_base)?;
let start = media_time::MediaTime::from_rational(packet.pts(), &time_base)?;
let end = start + duration;
let mut skip = true;
if let Some(spritesheet_manager) = &mut spritesheet_manager {
if spritesheet_manager.fulfils_frame_interval(end) {
skip = false;
}
}
if let Some(timelens_manager) = &mut timelens_manager {
if timelens_manager.fulfils_frame_interval(end) {
skip = false;
}
}
if !skip {
codec_context codec_context
.in_packet(&mut packet) .in_packet(&mut packet)
.map_err(|error| format_err!("Could not load packet: {}", error))?; .map_err(|error| format_err!("Could not load packet: {}", error))?;
...@@ -124,6 +141,7 @@ pub fn extract( ...@@ -124,6 +141,7 @@ pub fn extract(
} }
} }
} }
}
if let Some(spritesheet_manager) = &mut spritesheet_manager { if let Some(spritesheet_manager) = &mut spritesheet_manager {
spritesheet_manager.end_frame(duration); spritesheet_manager.end_frame(duration);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment