From: Carl Hetherington Date: Tue, 16 May 2017 13:16:36 +0000 (+0100) Subject: FFmpegEncoder fixes: handle AV_CODEC_CAP_VARIABLE_FRAME_SIZE, fix typo in interleavin... X-Git-Tag: v2.11.6~34 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=793028f4f404d69a06ccaeec987174d04d0761ec;p=dcpomatic.git FFmpegEncoder fixes: handle AV_CODEC_CAP_VARIABLE_FRAME_SIZE, fix typo in interleaving, fix cut-and-paste error in avcodec_encode_audio2. --- diff --git a/src/lib/ffmpeg_encoder.cc b/src/lib/ffmpeg_encoder.cc index eb7d476a8..8e95c687f 100644 --- a/src/lib/ffmpeg_encoder.cc +++ b/src/lib/ffmpeg_encoder.cc @@ -205,7 +205,7 @@ FFmpegEncoder::go () packet.data = 0; packet.size = 0; - avcodec_encode_audio2 (_video_codec_context, &packet, 0, &got_packet); + avcodec_encode_audio2 (_audio_codec_context, &packet, 0, &got_packet); if (got_packet) { packet.stream_index = 0; av_interleaved_write_frame (_format_context, &packet); @@ -284,24 +284,31 @@ FFmpegEncoder::video (shared_ptr video, DCPTime time) } } +/** Called when the player gives us some audio */ void FFmpegEncoder::audio (shared_ptr audio, DCPTime) { _pending_audio->append (audio); - while (_pending_audio->frames() >= _audio_codec_context->frame_size) { - audio_frame (_audio_codec_context->frame_size); + int frame_size = _audio_codec_context->frame_size; + if (frame_size == 0) { + /* codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE */ + frame_size = 2000; + } + + while (_pending_audio->frames() >= frame_size) { + audio_frame (frame_size); } } void FFmpegEncoder::audio_frame (int size) { + DCPOMATIC_ASSERT (size); + AVFrame* frame = av_frame_alloc (); DCPOMATIC_ASSERT (frame); - DCPOMATIC_ASSERT (size); - int const channels = _audio_codec_context->channels; DCPOMATIC_ASSERT (channels); @@ -321,7 +328,7 @@ FFmpegEncoder::audio_frame (int size) { int16_t* q = reinterpret_cast (samples); for (int i = 0; i < size; ++i) { - for (int j = 0; j < channels; ++i) { + for (int j = 0; j < channels; ++j) { *q++ = p[j][i] * 32767; } }