From 375c120d30456738897c4bd775e38aa1db7d239c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 22 Dec 2022 13:29:02 -0500 Subject: v3.1 --- src/ffmpeg_backend.cpp | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'src/ffmpeg_backend.cpp') 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; - } - } - } - */ } -- cgit v1.2.3