Skip to content

Commit dda33b6

Browse files
committed
Fill in guessed PTS values for decoders that don't output them at all (avi and probably other obscure CFR containers)
1 parent 40f8d6b commit dda33b6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project('BestSource', 'cpp',
22
default_options: ['buildtype=release', 'b_ndebug=if-release', 'cpp_std=c++17'],
33
license: 'MIT',
44
meson_version: '>=0.53.0',
5-
version: '11.0',
5+
version: '12.0',
66
)
77

88
api_sources = files(

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifndef VERSION_H
2222
#define VERSION_H
2323

24-
#define BEST_SOURCE_VERSION_MAJOR 11
24+
#define BEST_SOURCE_VERSION_MAJOR 12
2525
#define BEST_SOURCE_VERSION_MINOR 0
2626

2727
#endif

src/videosource.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,12 +1052,14 @@ bool BestVideoSource::IndexTrack(const ProgressFunction &Progress) {
10521052
TrackIndex.LastFrameDuration = 0;
10531053
bool HasKeyFrames = false;
10541054
bool HasEarlyKeyFrames = false;
1055+
bool HasValidPTS = false;
10551056

10561057
while (true) {
10571058
AVFrame *F = Decoder->GetNextFrame();
10581059
if (!F)
10591060
break;
10601061

1062+
HasValidPTS = HasValidPTS || (F->pts != AV_NOPTS_VALUE);
10611063
HasKeyFrames = HasKeyFrames || !!(F->flags & AV_FRAME_FLAG_KEY);
10621064
if (TrackIndex.Frames.size() < 100)
10631065
HasEarlyKeyFrames = HasKeyFrames;
@@ -1082,6 +1084,22 @@ bool BestVideoSource::IndexTrack(const ProgressFunction &Progress) {
10821084
} else if (!HasEarlyKeyFrames) {
10831085
BSDebugPrint("No keyframes found in the first 100 frames when indexing, this may or may not cause performance problems when seeking");
10841086
}
1087+
1088+
// Fill out default incrementing PTS for files with no valid values
1089+
if (!HasValidPTS) {
1090+
size_t Step = VP.Duration / TrackIndex.Frames.size();
1091+
if (Step < 1 || VP.Duration % TrackIndex.Frames.size() != 0) {
1092+
// Assertion here because it probably doesn't exist
1093+
assert(false);
1094+
Step = 1;
1095+
}
1096+
1097+
int64_t PTS = 0;
1098+
for (auto &Iter : TrackIndex.Frames) {
1099+
Iter.PTS = PTS;
1100+
PTS += Step;
1101+
}
1102+
}
10851103
}
10861104

10871105
return !TrackIndex.Frames.empty();

0 commit comments

Comments
 (0)