From e9333c8749e36819a7b6ba55284475a0de355f30 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 27 Oct 2014 23:31:51 -0700 Subject: [PATCH] Fix audio frame pts --- src/platform/ffmpeg/ffmpeg-encoder.c | 4 +++- src/platform/ffmpeg/ffmpeg-encoder.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/ffmpeg/ffmpeg-encoder.c b/src/platform/ffmpeg/ffmpeg-encoder.c index 73a0f41d1..5a0cbe5cf 100644 --- a/src/platform/ffmpeg/ffmpeg-encoder.c +++ b/src/platform/ffmpeg/ffmpeg-encoder.c @@ -241,6 +241,7 @@ void FFmpegEncoderClose(struct FFmpegEncoder* encoder) { encoder->currentAudioSample = 0; encoder->currentAudioFrame = 0; + encoder->nextAudioPts = 0; encoder->currentVideoFrame = 0; } @@ -272,7 +273,8 @@ void _ffmpegPostAudioFrame(struct GBAAVStream* stream, int32_t left, int32_t rig avresample_read(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize); AVRational timeBase = { 1, PREFERRED_SAMPLE_RATE }; - encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame, timeBase, encoder->audioStream->time_base); + encoder->audioFrame->pts = encoder->nextAudioPts; + encoder->nextAudioPts = av_rescale_q(encoder->currentAudioFrame, timeBase, encoder->audioStream->time_base); AVPacket packet; av_init_packet(&packet); diff --git a/src/platform/ffmpeg/ffmpeg-encoder.h b/src/platform/ffmpeg/ffmpeg-encoder.h index 3b10eb19d..02d5fc0da 100644 --- a/src/platform/ffmpeg/ffmpeg-encoder.h +++ b/src/platform/ffmpeg/ffmpeg-encoder.h @@ -29,6 +29,7 @@ struct FFmpegEncoder { AVFrame* audioFrame; size_t currentAudioSample; int64_t currentAudioFrame; + int64_t nextAudioPts; AVAudioResampleContext* resampleContext; AVStream* audioStream;