diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-05-16 14:16:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-05-16 14:16:36 +0100 |
| commit | 793028f4f404d69a06ccaeec987174d04d0761ec (patch) | |
| tree | 2064f2017cec7ae7758e55042f8457418a3b007b /src | |
| parent | 8040705763d2c7f5d0bee28a965802d0b2b6d906 (diff) | |
FFmpegEncoder fixes: handle AV_CODEC_CAP_VARIABLE_FRAME_SIZE, fix typo in interleaving, fix cut-and-paste error in avcodec_encode_audio2.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/ffmpeg_encoder.cc | 19 |
1 files changed, 13 insertions, 6 deletions
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<PlayerVideo> video, DCPTime time) } } +/** Called when the player gives us some audio */ void FFmpegEncoder::audio (shared_ptr<AudioBuffers> 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<int16_t*> (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; } } |
