Skip to content

Commit

Permalink
Add an ability to retry rewind to the one before the last keyframe (#…
Browse files Browse the repository at this point in the history
…5669)

- sometimes the rewind to one before the last keyframe leads
  to rewinding to this keyframe. With this change when it happens
  DALI tries to iteratively rewind to one before the last, two
  before the last, and so on...

Signed-off-by: Janusz Lisiecki <[email protected]>
  • Loading branch information
JanuszL authored Oct 14, 2024
1 parent 15afbdd commit 6695f6c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions dali/operators/reader/loader/video_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ void VideoLoader::read_file() {

bool is_first_frame = true;
int last_key_frame = -1;
int previous_last_key_frame = -1;
bool previous_last_key_frame_updated = false;
bool key = false;
bool seek_must_succeed = false;
// how many key frames following the last requested frames we saw so far
Expand Down Expand Up @@ -607,18 +609,30 @@ void VideoLoader::read_file() {
"already 0");
}

if (previous_last_key_frame < 0) {
previous_last_key_frame = last_key_frame - 1;
previous_last_key_frame_updated = true;
}
if (previous_last_key_frame_updated == false) {
--previous_last_key_frame;
}
LOG_LINE << "Decoding not started, seek to preceding key frame, "
<< "current frame " << frame
<< ", last key frame " << last_key_frame
<< ", is_key " << key << std::endl;
seek(file, last_key_frame - 1);
<< "current frame " << frame
<< ", look for a key frame before " << previous_last_key_frame
<< ", is_key " << key << std::endl;
seek(file, previous_last_key_frame);
previous_last_key_frame_updated = false;
frames_send = 0;
last_key_frame = -1;
continue;
}

if (key) {
last_key_frame = frame;
if (frame < previous_last_key_frame) {
previous_last_key_frame = frame;
previous_last_key_frame_updated = true;
}
}

int pkt_frames = 1;
Expand Down

0 comments on commit 6695f6c

Please sign in to comment.