# Patch to fix compilation with FFmpeg 0.10.x
# See https://github.com/Motion-Project/motion/commit/52737737776a4622c929334f762cd78d308c2828
# See https://github.com/Motion-Project/motion/commit/58627b05aad3f978a97b36ac05f9917015030602
diff -urNad motion-3.2.12-orig//ffmpeg.c motion-3.2.12/ffmpeg.c
--- motion-3.2.12-orig//ffmpeg.c	2010-06-01 09:48:23.000000000 +0300
+++ motion-3.2.12/ffmpeg.c	2017-02-26 18:59:27.000000000 +0200
@@ -36,7 +36,6 @@
 #    endif /* __GNUC__ */
 #endif /* LIBAVCODEC_BUILD > 4680 */
 
-
 #if LIBAVFORMAT_BUILD >= 4616
 /* The API for av_write_frame changed with FFmpeg version 0.4.9pre1.
  * It now uses an AVPacket struct instead of direct parameters to the
@@ -228,7 +227,9 @@
     mpeg1_file_protocol.url_close = file_protocol.url_close;
 
     /* Register the append file protocol. */
-#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8)
+#if LIBAVFORMAT_BUILD >= (53<<16 | 32<<8)
+    av_register_protocol2(&mpeg1_file_protocol, sizeof(mpeg1_file_protocol));
+#elif LIBAVFORMAT_BUILD >= (52<<16 | 31<<8)
     av_register_protocol(&mpeg1_file_protocol);
 #else
     register_protocol(&mpeg1_file_protocol);
@@ -258,7 +259,7 @@
         /* We use "mpeg1video" for raw mpeg1 format. Using "mpeg" would
          * result in a muxed output file, which isn't appropriate here.
          */
-        of = guess_format("mpeg1video", NULL, NULL);
+        of = av_guess_format("mpeg1video", NULL, NULL);        
         if (of) {
             /* But we want the trailer to be correctly written. */
             of->write_trailer = mpeg1_write_trailer;
@@ -270,24 +271,24 @@
 #endif
     } else if (strcmp(codec, "mpeg4") == 0) {
         ext = ".avi";
-        of = guess_format("avi", NULL, NULL);
+        of = av_guess_format("avi", NULL, NULL);
     } else if (strcmp(codec, "msmpeg4") == 0) {
         ext = ".avi";
-        of = guess_format("avi", NULL, NULL);
+        of = av_guess_format("avi", NULL, NULL);
         if (of) {
             /* Manually override the codec id. */
             of->video_codec = CODEC_ID_MSMPEG4V2;
         }
     } else if (strcmp(codec, "swf") == 0) {
         ext = ".swf";
-        of = guess_format("swf", NULL, NULL);
+        of = av_guess_format("swf", NULL, NULL);
     } else if (strcmp(codec, "flv") == 0) {
         ext = ".flv";
-        of = guess_format("flv", NULL, NULL);
+        of = av_guess_format("flv", NULL, NULL);
         of->video_codec = CODEC_ID_FLV1;
     } else if (strcmp(codec, "ffv1") == 0) {
         ext = ".avi";
-        of = guess_format("avi", NULL, NULL);
+        of = av_guess_format("avi", NULL, NULL);
         if (of) {
             /* Use the FFMPEG Lossless Video codec (experimental!).
                Requires strict_std_compliance to be <= -2 */
@@ -295,7 +296,7 @@
         }
     } else if (strcmp(codec, "mov") == 0) {
         ext = ".mov";
-        of = guess_format("mov", NULL, NULL);        
+        of = av_guess_format("mov", NULL, NULL);        
     } else {
         motion_log(LOG_ERR, 0, "ffmpeg_video_codec option value %s is not supported", codec);
         return NULL;
@@ -377,7 +378,11 @@
 
     ffmpeg->c     = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st);
     c->codec_id   = ffmpeg->oc->oformat->video_codec;
+#if LIBAVCODEC_VERSION_MAJOR < 53    
     c->codec_type = CODEC_TYPE_VIDEO;
+#else
+    c->codec_type = AVMEDIA_TYPE_VIDEO;
+#endif    
     is_mpeg1      = c->codec_id == CODEC_ID_MPEG1VIDEO;
 
     if (strcmp(ffmpeg_video_codec, "ffv1") == 0)
@@ -646,7 +651,11 @@
     if (ffmpeg->oc->oformat->flags & AVFMT_RAWPICTURE) {
         /* raw video case. The API will change slightly in the near future for that */
 #ifdef FFMPEG_AVWRITEFRAME_NEWAPI
+#if LIBAVCODEC_VERSION_MAJOR < 53        
         pkt.flags |= PKT_FLAG_KEY;
+#else
+        pkt.flags |= AV_PKT_FLAG_KEY;  
+#endif
         pkt.data = (uint8_t *)pic;
         pkt.size = sizeof(AVPicture);
         ret = av_write_frame(ffmpeg->oc, &pkt);
@@ -667,7 +676,11 @@
 #ifdef FFMPEG_AVWRITEFRAME_NEWAPI
             pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts;
             if (AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->key_frame) {
+#if LIBAVCODEC_VERSION_MAJOR < 53                
                 pkt.flags |= PKT_FLAG_KEY;
+#else
+                pkt.flags |= AV_PKT_FLAG_KEY;
+#endif
             }
             pkt.data = ffmpeg->video_outbuf;
             pkt.size = out_size;
