UPDATE: opencv - FFmpeg API

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

UPDATE: opencv - FFmpeg API

Brad Smith-14
Update API usage to deal with current vs new FFmpeg API.


Index: Makefile
===================================================================
RCS file: /home/cvs/ports/graphics/opencv/Makefile,v
retrieving revision 1.45
diff -u -p -u -p -r1.45 Makefile
--- Makefile 24 Oct 2018 14:28:06 -0000 1.45
+++ Makefile 18 Feb 2019 04:31:10 -0000
@@ -16,7 +16,7 @@ PKGNAME-main = ${PKGNAME}
 PKGNAME-docs = opencv-docs-$V
 PKGNAME-java = opencv-java-$V
 REVISION-java = 1
-REVISION-main = 1
+REVISION-main = 2
 REVISION-docs = 0
 
 .for i in opencv_calib3d opencv_contrib opencv_core opencv_features2d \
Index: patches/patch-modules_highgui_src_cap_ffmpeg_impl_hpp
===================================================================
RCS file: patches/patch-modules_highgui_src_cap_ffmpeg_impl_hpp
diff -N patches/patch-modules_highgui_src_cap_ffmpeg_impl_hpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-modules_highgui_src_cap_ffmpeg_impl_hpp 18 Feb 2019 04:30:26 -0000
@@ -0,0 +1,107 @@
+$OpenBSD$
+
+- Fix build with FFmpeg 4.0
+- videoio(ffmpeg): specify stream->time_base
+
+Index: modules/highgui/src/cap_ffmpeg_impl.hpp
+--- modules/highgui/src/cap_ffmpeg_impl.hpp.orig
++++ modules/highgui/src/cap_ffmpeg_impl.hpp
+@@ -173,6 +173,10 @@ extern "C" {
+ #define AV_PIX_FMT_GRAY16BE PIX_FMT_GRAY16BE
+ #endif
+
++#ifndef PKT_FLAG_KEY
++#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
++#endif
++
+ #if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 \
+     ? CALC_FFMPEG_VERSION(52, 38, 100) : CALC_FFMPEG_VERSION(52, 13, 0))
+ #define USE_AV_FRAME_GET_BUFFER 1
+@@ -1481,13 +1485,20 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
+     // some formats want stream headers to be seperate
+     if(oc->oformat->flags & AVFMT_GLOBALHEADER)
+     {
++#if LIBAVCODEC_BUILD > CALC_FFMPEG_VERSION(56, 35, 0)
++        c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
++#else
+         c->flags |= CODEC_FLAG_GLOBAL_HEADER;
++#endif
+     }
+ #endif
+
+ #if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(52, 42, 0)
+     st->avg_frame_rate = (AVRational){frame_rate, frame_rate_base};
+ #endif
++#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 20, 0)
++    st->time_base = c->time_base;
++#endif
+
+     return st;
+ }
+@@ -1509,23 +1520,24 @@ static int icv_av_write_frame_FFMPEG( AVFormatContext
+ #endif
+     int ret = OPENCV_NO_FRAMES_WRITTEN_CODE;
+
+-    if (oc->oformat->flags & AVFMT_RAWPICTURE) {
++#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
++    if (oc->oformat->flags & AVFMT_RAWPICTURE)
++    {
+         /* raw video case. The API will change slightly in the near
+            futur for that */
+         AVPacket pkt;
+         av_init_packet(&pkt);
+
+-#ifndef PKT_FLAG_KEY
+-#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
+-#endif
+-
+         pkt.flags |= PKT_FLAG_KEY;
+         pkt.stream_index= video_st->index;
+         pkt.data= (uint8_t *)picture;
+         pkt.size= sizeof(AVPicture);
+
+         ret = av_write_frame(oc, &pkt);
+-    } else {
++    }
++    else
++#endif
++    {
+         /* encode the image */
+         AVPacket pkt;
+         av_init_packet(&pkt);
+@@ -1683,7 +1695,9 @@ void CvVideoWriter_FFMPEG::close()
+     /* write the trailer, if any */
+     if(ok && oc)
+     {
+-        if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 )
++#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
++        if (!(oc->oformat->flags & AVFMT_RAWPICTURE))
++#endif
+         {
+             for(;;)
+             {
+@@ -1917,7 +1931,10 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
+
+     outbuf = NULL;
+
+-    if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
++#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
++    if (!(oc->oformat->flags & AVFMT_RAWPICTURE))
++#endif
++    {
+         /* allocate output buffer */
+         /* assume we will never get codec output with more than 4 bytes per pixel... */
+         outbuf_size = width*height*4;
+@@ -2211,7 +2228,11 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVF
+         // some formats want stream headers to be seperate
+         if (oc->oformat->flags & AVFMT_GLOBALHEADER)
+         {
+-            c->flags |= CODEC_FLAG_GLOBAL_HEADER;
++            #if LIBAVCODEC_BUILD > CALC_FFMPEG_VERSION(56, 35, 0)
++                c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
++            #else
++                c->flags |= CODEC_FLAG_GLOBAL_HEADER;
++            #endif
+         }
+     #endif
+