Update for newer FFmpeg API.

ok ajacoutot@
This commit is contained in:
brad 2013-01-19 10:13:15 +00:00
parent 87fe7baac4
commit 52236907d4
2 changed files with 214 additions and 35 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.16 2012/12/29 20:49:17 landry Exp $
# $OpenBSD: Makefile,v 1.17 2013/01/19 10:13:15 brad Exp $
ONLY_FOR_ARCHS= ${GCC4_ARCHS}
@ -11,7 +11,7 @@ COMMENT-docs= documentation for OpenCV
V= 2.2.0
DISTNAME= OpenCV-$V
PKGNAME-main= opencv-$V
REVISION-main= 7
REVISION-main= 8
PKGNAME-docs= opencv-docs-$V
REVISION-docs= 1
CATEGORIES= graphics devel
@ -42,17 +42,15 @@ PERMIT_DISTFILES_FTP= Yes
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=opencvlibrary/}
EXTRACT_SUFX= .tar.bz2
WANTLIB += GL Half Iex IlmImf Imath X11 Xcomposite Xcursor
WANTLIB += Xdamage Xext Xfixes Xi Xinerama Xrandr Xrender
WANTLIB += atk-1.0 avcodec avformat avutil bz2 c cairo
WANTLIB += expat fontconfig freetype gdk-x11-2.0 gdk_pixbuf-2.0
WANTLIB += gio-2.0 glib-2.0 gmodule-2.0 gobject-2.0 gsm gstapp-0.10
WANTLIB += gstbase-0.10 gstreamer-0.10 gstvideo-0.10 gthread-2.0
WANTLIB += gtk-x11-2.0 jasper jpeg m mp3lame ogg orc-0.4 pango-1.0
WANTLIB += pangocairo-1.0 pangoft2-1.0 pixman-1 png pthread pthread-stubs
WANTLIB += schroedinger-1.0 speex stdc++ swscale theoradec theoraenc
WANTLIB += tiff vorbis vorbisenc vpx x264 xcb xcb-render xcb-shm
WANTLIB += xml2 z ${MODPY_WANTLIB}
WANTLIB += GL Half Iex IlmImf Imath X11 Xcomposite Xcursor Xdamage
WANTLIB += Xext Xfixes Xi Xinerama Xrandr Xrender atk-1.0 avcodec
WANTLIB += avformat avutil bz2 c cairo expat fontconfig freetype
WANTLIB += gdk-x11-2.0 gdk_pixbuf-2.0 gio-2.0 glib-2.0 gmodule-2.0
WANTLIB += gobject-2.0 gstapp-0.10 gstbase-0.10 gstreamer-0.10
WANTLIB += gstvideo-0.10 gthread-2.0 gtk-x11-2.0 jasper jpeg m
WANTLIB += pango-1.0 pangocairo-1.0 pangoft2-1.0 pixman-1 png
WANTLIB += pthread pthread-stubs stdc++ swscale tiff xcb
WANTLIB += xcb-render xcb-shm xml2 z ${MODPY_WANTLIB}
MODULES= devel/cmake \
devel/gettext \
@ -65,7 +63,7 @@ LIB_DEPENDS-main= multimedia/gstreamer-0.10/plugins-base \
x11/gtk+2 \
graphics/ilmbase \
graphics/openexr \
graphics/ffmpeg
graphics/ffmpeg>=20121026
WANTLIB-docs= # empty
LIB_DEPENDS-docs= # empty

View File

@ -1,9 +1,9 @@
$OpenBSD: patch-modules_highgui_src_cap_ffmpeg_cpp,v 1.5 2012/05/03 06:35:31 ajacoutot Exp $
$OpenBSD: patch-modules_highgui_src_cap_ffmpeg_cpp,v 1.6 2013/01/19 10:13:15 brad Exp $
Update for newer FFmpeg API.
--- modules/highgui/src/cap_ffmpeg.cpp.orig Sat Dec 4 22:35:25 2010
+++ modules/highgui/src/cap_ffmpeg.cpp Wed May 2 22:28:51 2012
+++ modules/highgui/src/cap_ffmpeg.cpp Fri Jan 18 16:45:53 2013
@@ -53,7 +53,7 @@ extern "C" {
#define UINT64_C
#define __STDC_CONSTANT_MACROS
@ -13,7 +13,88 @@ Update for newer FFmpeg API.
#include <stdint.h>
#endif
#include <errno.h>
@@ -466,7 +466,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
@@ -109,6 +109,8 @@ extern "C" {
}
+#define CALC_FFMPEG_VERSION(a,b,c) ( a<<16 | b<<8 | c )
+
#if defined _MSC_VER && _MSC_VER >= 1200
#pragma warning( default: 4244 4510 4512 4610 )
#endif
@@ -384,7 +386,11 @@ void CvCapture_FFMPEG::close()
if( ic )
{
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 24, 2)
+ avformat_close_input(&ic);
+#else
av_close_input_file(ic);
+#endif
ic = NULL;
}
@@ -413,18 +419,35 @@ bool CvCapture_FFMPEG::reopen()
#else
avcodec_close( &video_st->codec );
#endif
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 24, 2)
+ avformat_close_input(&ic);
+#else
av_close_input_file(ic);
+#endif
// reopen video
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+ avformat_open_input(&ic, filename, NULL, NULL);
+#else
av_open_input_file(&ic, filename, NULL, 0, NULL);
+#endif
+
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 3, 0)
+ avformat_find_stream_info(ic, NULL);
+#else
av_find_stream_info(ic);
+#endif
#if LIBAVFORMAT_BUILD > 4628
AVCodecContext *enc = ic->streams[video_stream]->codec;
#else
AVCodecContext *enc = &ic->streams[video_stream]->codec;
#endif
AVCodec *codec = avcodec_find_decoder(enc->codec_id);
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+ avcodec_open2(enc, codec, NULL);
+#else
avcodec_open(enc, codec);
+#endif
video_st = ic->streams[video_stream];
// reset framenumber to zero
@@ -449,12 +472,22 @@ bool CvCapture_FFMPEG::open( const char* _filename )
// av_log_level = AV_LOG_QUIET;
#endif
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+ int err = avformat_open_input(&ic, _filename, NULL, NULL);
+#else
int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
+#endif
+
if (err < 0) {
CV_WARN("Error opening file");
goto exit_func;
}
- err = av_find_stream_info(ic);
+ err =
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 3, 0)
+ avformat_find_stream_info(ic, NULL);
+#else
+ av_find_stream_info(ic);
+#endif
if (err < 0) {
CV_WARN("Could not find codec parameters");
goto exit_func;
@@ -466,10 +499,15 @@ bool CvCapture_FFMPEG::open( const char* _filename )
AVCodecContext *enc = &ic->streams[i]->codec;
#endif
@ -21,20 +102,28 @@ Update for newer FFmpeg API.
+ if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) {
AVCodec *codec = avcodec_find_decoder(enc->codec_id);
if (!codec ||
avcodec_open(enc, codec) < 0)
@@ -551,9 +551,9 @@ bool CvCapture_FFMPEG::grabFrame()
- avcodec_open(enc, codec) < 0)
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+ avcodec_open2(enc, codec, NULL)
+#else
+ avcodec_open(enc, codec)
+#endif
+ < 0)
goto exit_func;
video_stream = i;
video_st = ic->streams[i];
@@ -550,7 +588,9 @@ bool CvCapture_FFMPEG::grabFrame()
continue;
}
#if LIBAVFORMAT_BUILD > 4628
- avcodec_decode_video(video_st->codec,
+ avcodec_decode_video2(video_st->codec,
-#if LIBAVFORMAT_BUILD > 4628
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
+ avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
+#elif LIBAVFORMAT_BUILD > 4628
avcodec_decode_video(video_st->codec,
picture, &got_picture,
- packet.data, packet.size);
+ &packet);
#else
avcodec_decode_video(&video_st->codec,
picture, &got_picture,
@@ -806,15 +806,15 @@ class CvVideoWriter_FFMPEG : public CvVideoWriter (pro
packet.data, packet.size);
@@ -806,15 +846,15 @@ class CvVideoWriter_FFMPEG : public CvVideoWriter (pro
static const char * icvFFMPEGErrStr(int err)
{
switch(err) {
@ -55,7 +144,21 @@ Update for newer FFmpeg API.
return "Memory allocation error";
default:
break;
@@ -899,7 +899,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
@@ -885,8 +925,12 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
int frame_rate, frame_rate_base;
AVCodec *codec;
-
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
+ st = avformat_new_stream(oc, 0);
+#else
st = av_new_stream(oc, 0);
+#endif
+
if (!st) {
CV_WARN("Could not allocate stream");
return NULL;
@@ -899,7 +943,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
#endif
#if LIBAVFORMAT_BUILD > 4621
@ -64,7 +167,7 @@ Update for newer FFmpeg API.
#else
c->codec_id = oc->oformat->video_codec;
#endif
@@ -911,7 +911,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
@@ -911,7 +955,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatC
//if(codec_tag) c->codec_tag=codec_tag;
codec = avcodec_find_encoder(c->codec_id);
@ -73,7 +176,7 @@ Update for newer FFmpeg API.
/* put sample parameters */
c->bit_rate = bitrate;
@@ -998,7 +998,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, A
@@ -998,7 +1042,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, A
AVPacket pkt;
av_init_packet(&pkt);
@ -82,7 +185,7 @@ Update for newer FFmpeg API.
pkt.stream_index= video_st->index;
pkt.data= (uint8_t *)picture;
pkt.size= sizeof(AVPicture);
@@ -1018,7 +1018,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, A
@@ -1018,7 +1062,7 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, A
pkt.pts = c->coded_frame->pts;
#endif
if(c->coded_frame->key_frame)
@ -91,16 +194,38 @@ Update for newer FFmpeg API.
pkt.stream_index= video_st->index;
pkt.data= outbuf;
pkt.size= out_size;
@@ -1215,7 +1215,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
@@ -1180,12 +1224,15 @@ void CvVideoWriter_FFMPEG::close()
if (!(fmt->flags & AVFMT_NOFILE)) {
/* close the output file */
-
+#if LIBAVCODEC_VERSION_INT < ((52<<16)+(123<<8)+0)
#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(49<<8)+0)
url_fclose(oc->pb);
#else
url_fclose(&oc->pb);
#endif
+#else
+ avio_close(oc->pb);
+#endif
}
@@ -1215,7 +1262,13 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
av_register_all ();
/* auto detect the output format from the name and fourcc code. */
- fmt = guess_format(NULL, filename, NULL);
+
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
+ fmt = av_guess_format(NULL, filename, NULL);
+#else
fmt = guess_format(NULL, filename, NULL);
+#endif
+
if (!fmt)
return false;
@@ -1238,7 +1238,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
@@ -1238,7 +1291,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
#endif
// alloc memory for context
@ -109,3 +234,59 @@ Update for newer FFmpeg API.
assert (oc);
/* set file name */
@@ -1279,11 +1332,15 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
/* set the output parameters (must be done even if no
parameters). */
+#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
if (av_set_parameters(oc, NULL) < 0) {
CV_Error(CV_StsBadArg, "Invalid output format parameters");
}
+#endif
+#if 0
dump_format(oc, 0, filename, 1);
+#endif
/* now that all the parameters are set, we can open the audio and
video codecs and allocate the necessary encode buffers */
@@ -1308,7 +1365,13 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
}
/* open the codec */
- if ( (err=avcodec_open(c, codec)) < 0) {
+ if ( (err=
+#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
+ avcodec_open2(c, codec, NULL)
+#else
+ avcodec_open(c, codec)
+#endif
+ ) < 0) {
char errtext[256];
sprintf(errtext, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err));
CV_Error(CV_StsBadArg, errtext);
@@ -1345,13 +1408,23 @@ bool CvVideoWriter_FFMPEG::open( const char * filename
/* open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE)) {
- if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
+ if (
+#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
+ url_fopen(&oc->pb, filename, URL_WRONLY)
+#else
+ avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)
+#endif
+ < 0) {
CV_Error(CV_StsBadArg, "Couldn't open output file for writing");
}
}
/* write the stream header, if any */
+#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
+ avformat_write_header(oc, NULL);
+#else
av_write_header( oc );
+#endif
return true;
}