Skip to content

Commit e4097ac

Browse files
committed
Fallback to best_effort_timestamp in case of invalid PTS
If the input video has invalid PTS, the current precise seek fails except when seeking into t=0. This commit updates the discard mechanism to fallback to `best_effort_timestamp` in such cases. `best_effort_timestamp` is just the number of frames went through decoder starting from the beginning of the file. This means if the input file is very long, but seeking towards the end of the file, the StreamReader still decodes all the frames. For videos with valid PTS, `best_effort_timestamp` should be same as `pts`.
1 parent cbd3543 commit e4097ac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

torchaudio/csrc/ffmpeg/stream_reader/stream_processor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ int StreamProcessor::process_packet(AVPacket* packet) {
102102
// and just not discard any.
103103
//
104104
// Note: discard_before_pts < 0 is UB.
105-
if (discard_before_pts <= 0 || pFrame1->pts >= discard_before_pts) {
105+
if (
106+
discard_before_pts <= 0 ||
107+
pFrame1->pts >= discard_before_pts ||
108+
pFrame1->best_effort_timestamp >= discard_before_pts) {
106109
send_frame(pFrame1);
107110
}
108111

0 commit comments

Comments
 (0)