FFmpeg: Fix encoding audio/video queue issues
Vicki Pfau vi@endrift.com
Tue, 18 Sep 2018 13:55:52 -0700
3 files changed,
7 insertions(+),
5 deletions(-)
M
CHANGES
→
CHANGES
@@ -55,6 +55,7 @@ - PSP2: Fix more issues causing poor audio
- GBA Memory: Fix Vast Fame support (taizou) (fixes mgba.io/i/1170) - GB, GBA Savedata: Fix unmasking savedata crash - GBA DMA: Fix temporal sorting of DMAs of different priorities + - FFmpeg: Fix encoding audio/video queue issues Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M
src/feature/ffmpeg/ffmpeg-encoder.c
→
src/feature/ffmpeg/ffmpeg-encoder.c
@@ -205,7 +205,6 @@
encoder->currentAudioSample = 0; encoder->currentAudioFrame = 0; encoder->currentVideoFrame = 0; - encoder->nextAudioPts = 0; AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0); #ifndef USE_LIBAV@@ -301,6 +300,7 @@ encoder->video->bit_rate = encoder->videoBitrate;
encoder->video->width = encoder->width; encoder->video->height = encoder->height; encoder->video->time_base = (AVRational) { VIDEO_TOTAL_LENGTH, GBA_ARM7TDMI_FREQUENCY }; + encoder->video->framerate = (AVRational) { GBA_ARM7TDMI_FREQUENCY, VIDEO_TOTAL_LENGTH }; encoder->video->pix_fmt = encoder->pixFormat; encoder->video->gop_size = 60; encoder->video->max_b_frames = 3;@@ -457,14 +457,13 @@ int samples = swr_convert(encoder->resampleContext, encoder->audioFrame->data, encoder->postaudioBufferSize / channelSize,
(const uint8_t**) &encoder->audioBuffer, encoder->audioBufferSize / 4); #endif - encoder->audioFrame->pts = av_rescale_q(encoder->currentAudioFrame, encoder->audio->time_base, encoder->audioStream->time_base); + encoder->audioFrame->pts = encoder->currentAudioFrame; encoder->currentAudioFrame += samples; AVPacket packet; av_init_packet(&packet); packet.data = 0; packet.size = 0; - packet.pts = encoder->audioFrame->pts; int gotData; #ifdef FFMPEG_USE_PACKETS@@ -474,6 +473,9 @@ gotData = (gotData == 0) && packet.size;
#else avcodec_encode_audio2(encoder->audio, &packet, encoder->audioFrame, &gotData); #endif + packet.pts = av_rescale_q(encoder->audioFrame->pts, encoder->audio->time_base, encoder->audioStream->time_base); + packet.dts = packet.pts; + if (gotData) { if (encoder->absf) { AVPacket tempPacket;@@ -532,7 +534,6 @@ #if LIBAVCODEC_VERSION_MAJOR >= 55
av_frame_make_writable(encoder->videoFrame); #endif encoder->videoFrame->pts = av_rescale_q(encoder->currentVideoFrame, encoder->video->time_base, encoder->videoStream->time_base); - packet.pts = encoder->videoFrame->pts; ++encoder->currentVideoFrame; sws_scale(encoder->scaleContext, (const uint8_t* const*) &pixels, (const int*) &stride, 0, encoder->iheight, encoder->videoFrame->data, encoder->videoFrame->linesize);@@ -544,6 +545,7 @@ gotData = avcodec_receive_packet(encoder->video, &packet) == 0;
#else avcodec_encode_video2(encoder->video, &packet, encoder->videoFrame, &gotData); #endif + packet.pts = encoder->videoFrame->pts; if (gotData) { #ifndef FFMPEG_USE_PACKET_UNREF if (encoder->video->coded_frame->key_frame) {
M
src/feature/ffmpeg/ffmpeg-encoder.h
→
src/feature/ffmpeg/ffmpeg-encoder.h
@@ -56,7 +56,6 @@ size_t postaudioBufferSize;
AVFrame* audioFrame; size_t currentAudioSample; int64_t currentAudioFrame; - int64_t nextAudioPts; // TODO (0.6): Remove #ifdef USE_LIBAVRESAMPLE struct AVAudioResampleContext* resampleContext; #else