- AVPacket packet;
- av_init_packet (&packet);
- packet.data = 0;
- packet.size = 0;
-
- int got_packet;
-DCPOMATIC_DISABLE_WARNINGS
- avcodec_encode_video2 (_video_codec_context, &packet, 0, &got_packet);
-DCPOMATIC_ENABLE_WARNINGS
- if (got_packet) {
- packet.stream_index = 0;
- av_interleaved_write_frame (_format_context, &packet);
- } else {
+ int r = avcodec_send_frame (_video_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_("FFmpegFileEncoder::flush"), r);
+ }
+
+ ffmpeg::Packet packet;
+ r = avcodec_receive_packet (_video_codec_context, packet.get());
+ if (r == AVERROR_EOF) {