FFmpeg: Fix encoding audio/video queue issues

This commit is contained in:
Vicki Pfau 2018-09-18 13:55:52 -07:00
parent 108b0fc867
commit 751acd1637
3 changed files with 7 additions and 5 deletions

View File

@ -55,6 +55,7 @@ Bugfixes:
- 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)

View File

@ -205,7 +205,6 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
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 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
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 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
(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 @@ void _ffmpegPostAudioFrame(struct mAVStream* stream, int16_t left, int16_t right
#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 @@ void _ffmpegPostVideoFrame(struct mAVStream* stream, const color_t* pixels, size
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 @@ void _ffmpegPostVideoFrame(struct mAVStream* stream, const color_t* pixels, size
#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) {

View File

@ -56,7 +56,6 @@ struct FFmpegEncoder {
AVFrame* audioFrame;
size_t currentAudioSample;
int64_t currentAudioFrame;
int64_t nextAudioPts; // TODO (0.6): Remove
#ifdef USE_LIBAVRESAMPLE
struct AVAudioResampleContext* resampleContext;
#else