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.cpp42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/ffmpeg_backend.cpp b/src/ffmpeg_backend.cpp
index 821afce..a104714 100644
--- a/src/ffmpeg_backend.cpp
+++ b/src/ffmpeg_backend.cpp
@@ -253,7 +253,7 @@ void AV_Init(block_source *Source, av_info *AV, memory *Memory)
avcodec_flush_buffers(AV->Audio.CodecContext);
};
-uint32 AV_AudioTest(av_info *AV, void *Data, uint32 Size)
+uint32 AV_AudioTest(av_info *AV, void *Data, uint32 Size, real32 FPS, int32 InitialFrameToSeek)
{
AVChannelLayout ChannelLayout = {};
av_channel_layout_default(&ChannelLayout, 2);
@@ -261,12 +261,16 @@ uint32 AV_AudioTest(av_info *AV, void *Data, uint32 Size)
av_stream_info *Stream = &AV->Audio;
Assert(Stream->CodecContext->ch_layout.nb_channels == 2);
+ real32 TotalFrames = AV->SecondCount * FPS;
+ int64 SeekPTS = (int64)(((real64)InitialFrameToSeek / TotalFrames) * AV->PTSDuration);
+ int64 AveragePTS = AV->PTSDuration / TotalFrames;
+
int32 err = 0;
bool32 EndOfFile = 0;
while (err >= 0) {
if (AV_TryFrame(AV, Stream->CodecContext, &err, &EndOfFile, Stream->Index))
{
- if (AV->Frame->pts < Stream->Stream->start_time) {
+ if (AV->Frame->pts < Stream->Stream->start_time || AV->Frame->pts < SeekPTS) {
av_frame_unref(AV->Frame);
continue;
}
@@ -309,40 +313,6 @@ void AV_SeekAudio(av_info *AV, real32 FPS, int32 FrameToSeek)
Assert(FrameToSeek > -1)
int64 SeekSeconds = (int64)(FrameToSeek / (int32)(FPS + 0.5f) * AV_TIME_BASE);
av_seek_frame(AV->FileFormatContext, -1, SeekSeconds, AVSEEK_FLAG_BACKWARD);
-
- /*
- real32 TotalFrames = AV->SecondCount * FPS;
- int64 SeekPTS = (int64)(((real64)FrameToSeek / TotalFrames) * AV->PTSDuration);
- int64 AveragePTS = AV->PTSDuration / TotalFrames;
-
- int32 err = 0;
- bool32 EndOfFile = 0;
- while (err >= 0) {
- if (AV_TryFrame(AV, AV->Audio.CodecContext, &err, &EndOfFile))
- {
- int a = 0;
- }
- }
-
- while (err >= 0) {
- if (AV_TryFrame(AV, AV->Audio.CodecContext, &err, &EndOfFile, AV->Audio.Index))
- {
- // The first frame that gets loaded isn't always the actual
- // first frame, so we need to check until it's correct.
- if (FrameToSeek == 0 && AV->Frame->pts < AV->Audio.Stream->start_time) {
- av_frame_unref(AV->Frame);
- // printf("NON-START: avg: %li, real pts: %li", SeekPTS, AV->VideoFrame->pts);
- continue;
- }
-
- int64 Difference = AV->Frame->pts - SeekPTS;
- if (abs(Difference) < AveragePTS)
- {
- return;
- }
- }
- }
- */
}