summaryrefslogtreecommitdiff
path: root/src/ffmpeg_backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ffmpeg_backend.cpp')
-rw-r--r--src/ffmpeg_backend.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ffmpeg_backend.cpp b/src/ffmpeg_backend.cpp
index 510188b..b688725 100644
--- a/src/ffmpeg_backend.cpp
+++ b/src/ffmpeg_backend.cpp
@@ -159,10 +159,12 @@ void AV_GetDuration(av_info *AV, av_stream_info *Stream, uint64 *Duration, real3
int32 err = 0;
bool32 EndOfFile = 0;
uint64 TestDuration = 0;
+ uint64 BestTimestamp = 0;
while (err >= 0) {
if (AV_TryFrame(AV, Stream->CodecContext, &err, &EndOfFile, Stream->Index))
{
TestDuration = AV->Frame->pts;
+ BestTimestamp = AV->Frame->best_effort_timestamp;
}
av_frame_unref(AV->Frame);
if (EndOfFile)
@@ -174,8 +176,15 @@ void AV_GetDuration(av_info *AV, av_stream_info *Stream, uint64 *Duration, real3
if (Stream->Stream->nb_frames > 0) {
*SecondCount = Stream->Stream->nb_frames / FPS;
} else if (AV->Video.CodecContext) {
+#if 1
+ // NOTE(fox): I'm going to believe this is accurate. The
+ // AVFormatContext->duration estimate doesn't work when the video
+ // stream's frame count differs greatly from the file's.
+ *SecondCount = (real32)*Duration / (real32)Stream->Stream->time_base.den;
+#else
Assert(AV->FileFormatContext->duration > 0);
*SecondCount = (real32)AV->FileFormatContext->duration / 1000000LL;
+#endif
}
}
@@ -344,6 +353,7 @@ void AV_LoadVideoFrame(memory *Memory, block_source *Source, av_info *AV, int32
real32 TotalFrames = AV->SecondCount * Source->FPS;
int64 SeekPTS = (int64)(((real64)FrameToSeek / TotalFrames) * AV->PTSDuration);
+ SeekPTS += AV->Video.Stream->start_time;
int64 AveragePTS = AV->PTSDuration / TotalFrames;
bool32 EndOfFile = 0;