- AVPacket packet;
- av_init_packet (&packet);
- packet.data = 0;
- packet.size = 0;
- bool flushed = false;
-
- int got_packet;
-DCPOMATIC_DISABLE_WARNINGS
- avcodec_encode_audio2 (_codec_context, &packet, 0, &got_packet);
-DCPOMATIC_ENABLE_WARNINGS
- if (got_packet) {
- packet.stream_index = 0;
- av_interleaved_write_frame (_format_context, &packet);
- } else {
- flushed = true;
+ int r = avcodec_send_frame (_codec_context, nullptr);
+ if (r < 0 && r != AVERROR_EOF) {
+ /* We get EOF if we've already flushed the stream once */
+ throw EncodeError (N_("avcodec_send_frame"), N_("ExportAudioStream::flush"), r);
+ }
+
+ ffmpeg::Packet packet;
+ r = avcodec_receive_packet (_codec_context, packet.get());
+ if (r == AVERROR_EOF) {
+ return true;
+ } else if (r < 0) {
+ throw EncodeError (N_("avcodec_receive_packet"), N_("ExportAudioStream::flush"), r);