all repos — mgba @ e2d5b029be73bcd65c2e93bedf9e6e5040b1a4f6

mGBA Game Boy Advance Emulator

FFmpeg: Fix encoing AAC
Jeffrey Pfau jeffrey@endrift.com
Wed, 21 Sep 2016 11:05:51 -0700
commit

e2d5b029be73bcd65c2e93bedf9e6e5040b1a4f6

parent

07380684f0557ad9245b67e28d71119f5201d625

2 files changed, 26 insertions(+), 10 deletions(-)

jump to
M CHANGESCHANGES

@@ -5,6 +5,7 @@ - GB Video: Setting LYC=LY during mode 2 should trigger an IRQ

- GBA Cheats: Fix holding onto pointers that may get invalidated - Qt: Fix "close" button on Overrides view - Qt: Fix saving overrides + - FFmpeg: Fix encoding AAC Misc: - All: Only update version info if needed
M src/feature/ffmpeg/ffmpeg-encoder.csrc/feature/ffmpeg/ffmpeg-encoder.c

@@ -381,6 +381,11 @@ if (!encoder->context || !encoder->audioCodec) {

return; } + if (encoder->absf && !left) { + // XXX: AVBSF doesn't like silence. Figure out why. + left = 1; + } + encoder->audioBuffer[encoder->currentAudioSample * 2] = left; encoder->audioBuffer[encoder->currentAudioSample * 2 + 1] = right;

@@ -415,40 +420,50 @@ packet.size = 0;

int gotData; #ifdef FFMPEG_USE_PACKETS avcodec_send_frame(encoder->audio, encoder->audioFrame); - gotData = avcodec_receive_packet(encoder->audio, &packet) == 0; + gotData = avcodec_receive_packet(encoder->audio, &packet); + gotData = (gotData == 0) && packet.size; #else avcodec_encode_audio2(encoder->audio, &packet, encoder->audioFrame, &gotData); #endif if (gotData) { if (encoder->absf) { - AVPacket tempPacket = packet; + AVPacket tempPacket; #ifdef FFMPEG_USE_NEW_BSF - int success = av_bsf_send_packet(encoder->absf, &packet) && av_bsf_receive_packet(encoder->absf, &packet); + int success = av_bsf_send_packet(encoder->absf, &packet); + if (success >= 0) { + success = av_bsf_receive_packet(encoder->absf, &tempPacket); + } #else int success = av_bitstream_filter_filter(encoder->absf, encoder->audio, 0, &tempPacket.data, &tempPacket.size, packet.data, packet.size, 0); #endif - if (success > 0) { + + if (success >= 0) { #if LIBAVUTIL_VERSION_MAJOR >= 53 tempPacket.buf = av_buffer_create(tempPacket.data, tempPacket.size, av_buffer_default_free, 0, 0); #endif + #ifdef FFMPEG_USE_PACKET_UNREF - av_packet_unref(&packet); + av_packet_move_ref(&packet, &tempPacket); #else av_free_packet(&packet); + packet = tempPacket; #endif + + packet.stream_index = encoder->audioStream->index; + av_interleaved_write_frame(encoder->context, &packet); } - packet = tempPacket; + } else { + packet.stream_index = encoder->audioStream->index; + av_interleaved_write_frame(encoder->context, &packet); } - packet.stream_index = encoder->audioStream->index; - av_interleaved_write_frame(encoder->context, &packet); } #ifdef FFMPEG_USE_PACKET_UNREF - av_packet_unref(&packet); + av_packet_unref(&packet); #else - av_free_packet(&packet); + av_free_packet(&packet); #endif }