From 2ed2763a53bd6d2e82cc451ab43fdaf56da83caa Mon Sep 17 00:00:00 2001
From: John Stebbins <jstebbins.hb@gmail.com>
Date: Thu, 9 Feb 2017 09:29:16 -0700
Subject: [PATCH] libav: fix h.264 initial recovery point detection

Initial GOP of video was dropped during decode.
Fixes https://github.com/HandBrake/HandBrake/issues/520

(cherry picked from commit 9dfe1373a9d1cb37843f3ffbe88fd63b630026c6)
---
 contrib/ffmpeg/A05-h264-recovery.patch | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 contrib/ffmpeg/A05-h264-recovery.patch

diff --git a/contrib/ffmpeg/A05-h264-recovery.patch b/contrib/ffmpeg/A05-h264-recovery.patch
new file mode 100644
index 000000000..d27b35bdd
--- /dev/null
+++ b/contrib/ffmpeg/A05-h264-recovery.patch
@@ -0,0 +1,20 @@
+diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
+index 5137039..6d7aa7b 100644
+--- a/libavcodec/h264dec.c
++++ b/libavcodec/h264dec.c
+@@ -452,7 +452,6 @@ void ff_h264_flush_change(H264Context *h)
+     if (h->cur_pic_ptr)
+         h->cur_pic_ptr->reference = 0;
+     h->first_field = 0;
+-    ff_h264_sei_uninit(&h->sei);
+     h->recovery_frame = -1;
+     h->frame_recovered = 0;
+ }
+@@ -466,6 +465,7 @@ static void flush_dpb(AVCodecContext *avctx)
+     memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
+ 
+     ff_h264_flush_change(h);
++    ff_h264_sei_uninit(&h->sei);
+ 
+     for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
+         ff_h264_unref_picture(h, &h->DPB[i]);
-- 
2.40.0