- int frame_finished;
-DCPOMATIC_DISABLE_WARNINGS
- if (avcodec_decode_video2 (video_codec_context(), _frame, &frame_finished, &_packet) < 0 || !frame_finished) {
+ auto context = video_codec_context();
+
+ int r = avcodec_send_packet (context, packet);
+ if (r < 0 && !(r == AVERROR_EOF && !packet)) {
+ /* We could cope with AVERROR(EAGAIN) and re-send the packet but I think it should never happen.
+ * AVERROR_EOF can happen during flush if we've already sent a flush packet.
+ */
+ throw DecodeError (N_("avcodec_send_packet"), N_("FFmpegDecoder::decode_and_process_video_packet"), r);
+ }
+
+ r = avcodec_receive_frame (context, _frame);
+ if (r == AVERROR(EAGAIN) || r == AVERROR_EOF || (r < 0 && !packet)) {
+ /* More input is required, no more frames are coming, or we are flushing and there was
+ * some error which we just want to ignore.
+ */