Commit d87a56a6 authored by Andrey Morozov's avatar Andrey Morozov

added support new ffmpeg (0.8.X)

parent 680ec04b
rem gcc -Wall -shared -o opencv_ffmpeg.dll -O3 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32 -lpthreadGE2
gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32 gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32
set path=c:\apps\mingw64\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat64 -lavcodec64 -lavdevice64 -lswscale64 -lavutil64 -lavcore64 -lwsock32 set path=c:\apps\mingw64\bin;%path% & gcc -Wall -shared -o opencv_ffmpeg_64.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat64 -lavcodec64 -lavdevice64 -lswscale64 -lavutil64 -lavcore64 -lwsock32
\ No newline at end of file
...@@ -372,7 +372,9 @@ enum ...@@ -372,7 +372,9 @@ enum
// Properties of cameras available through GStreamer interface // Properties of cameras available through GStreamer interface
CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1 CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1
CV_CAP_PROP_PVAPI_MULTICASTIP = 300 // ip for anable multicast master mode. 0 for disable multicast CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast
CV_CAP_PROP_THREADS = 400
}; };
enum enum
......
...@@ -21,7 +21,8 @@ enum ...@@ -21,7 +21,8 @@ enum
CV_FFMPEG_CAP_PROP_FRAME_HEIGHT=4, CV_FFMPEG_CAP_PROP_FRAME_HEIGHT=4,
CV_FFMPEG_CAP_PROP_FPS=5, CV_FFMPEG_CAP_PROP_FPS=5,
CV_FFMPEG_CAP_PROP_FOURCC=6, CV_FFMPEG_CAP_PROP_FOURCC=6,
CV_FFMPEG_CAP_PROP_FRAME_COUNT=7 CV_FFMPEG_CAP_PROP_FRAME_COUNT=7,
CV_FFMPEG_CAP_PROP_THREADS=8
}; };
......
...@@ -135,7 +135,7 @@ extern "C" { ...@@ -135,7 +135,7 @@ extern "C" {
#define PIX_FMT_RGBA32 PIX_FMT_RGB32 #define PIX_FMT_RGBA32 PIX_FMT_RGB32
#endif #endif
#define CALC_FFMPEG_VERSION(a,b,c) ( a<<16 | b<<8 | c )
char * FOURCC2str( int fourcc ) char * FOURCC2str( int fourcc )
{ {
...@@ -365,6 +365,7 @@ struct CvCapture_FFMPEG ...@@ -365,6 +365,7 @@ struct CvCapture_FFMPEG
and so the filename is needed to reopen the file on backward seeking. and so the filename is needed to reopen the file on backward seeking.
*/ */
char * filename; char * filename;
int count_threads;
}; };
...@@ -379,6 +380,7 @@ void CvCapture_FFMPEG::init() ...@@ -379,6 +380,7 @@ void CvCapture_FFMPEG::init()
memset( &frame, 0, sizeof(frame) ); memset( &frame, 0, sizeof(frame) );
filename = 0; filename = 0;
packet.data = NULL; packet.data = NULL;
count_threads = 1;
#if defined(HAVE_FFMPEG_SWSCALE) #if defined(HAVE_FFMPEG_SWSCALE)
img_convert_ctx = 0; img_convert_ctx = 0;
#endif #endif
...@@ -489,7 +491,13 @@ bool CvCapture_FFMPEG::open( const char* _filename ) ...@@ -489,7 +491,13 @@ bool CvCapture_FFMPEG::open( const char* _filename )
AVCodecContext *enc = &ic->streams[i]->codec; AVCodecContext *enc = &ic->streams[i]->codec;
#endif #endif
if( CODEC_TYPE_VIDEO == enc->codec_type && video_stream < 0) { avcodec_thread_init(enc, count_threads);
//#ifndef AVMEDIA_TYPE_VIDEO
// #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
//#endif
if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) {
AVCodec *codec = avcodec_find_decoder(enc->codec_id); AVCodec *codec = avcodec_find_decoder(enc->codec_id);
if (!codec || if (!codec ||
avcodec_open(enc, codec) < 0) avcodec_open(enc, codec) < 0)
...@@ -576,14 +584,18 @@ bool CvCapture_FFMPEG::grabFrame() ...@@ -576,14 +584,18 @@ bool CvCapture_FFMPEG::grabFrame()
continue; continue;
} }
#if LIBAVFORMAT_BUILD > 4628 #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 4, 0)
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
#else
#if LIBAVFORMAT_BUILD > 4628
avcodec_decode_video(video_st->codec, avcodec_decode_video(video_st->codec,
picture, &got_picture, picture, &got_picture,
packet.data, packet.size); packet.data, packet.size);
#else #else
avcodec_decode_video(&video_st->codec, avcodec_decode_video(&video_st->codec,
picture, &got_picture, picture, &got_picture,
packet.data, packet.size); packet.data, packet.size);
#endif
#endif #endif
if (got_picture) { if (got_picture) {
...@@ -702,12 +714,14 @@ double CvCapture_FFMPEG::getProperty( int property_id ) ...@@ -702,12 +714,14 @@ double CvCapture_FFMPEG::getProperty( int property_id )
return (double)video_st->codec.codec_tag; return (double)video_st->codec.codec_tag;
#endif #endif
break; break;
case CV_FFMPEG_CAP_PROP_THREADS:
return count_threads;
break;
} }
return 0; return 0;
} }
// this is a VERY slow fallback function, ONLY used if ffmpeg's av_seek_frame delivers no correct result! // this is a VERY slow fallback function, ONLY used if ffmpeg's av_seek_frame delivers no correct result!
bool CvCapture_FFMPEG::slowSeek( int framenumber ) bool CvCapture_FFMPEG::slowSeek( int framenumber )
{ {
...@@ -788,6 +802,12 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value ) ...@@ -788,6 +802,12 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
} }
break; break;
case CV_FFMPEG_CAP_PROP_THREADS:
{
count_threads = (int)value;
}
break;
default: default:
return false; return false;
} }
...@@ -824,6 +844,38 @@ struct CvVideoWriter_FFMPEG ...@@ -824,6 +844,38 @@ struct CvVideoWriter_FFMPEG
static const char * icvFFMPEGErrStr(int err) static const char * icvFFMPEGErrStr(int err)
{ {
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 4, 0)
switch(err) {
case AVERROR_BSF_NOT_FOUND:
return "Bitstream filter not found";
case AVERROR_DECODER_NOT_FOUND:
return "Decoder not found";
case AVERROR_DEMUXER_NOT_FOUND:
return "Demuxer not found";
case AVERROR_ENCODER_NOT_FOUND:
return "Encoder not found";
case AVERROR_EOF:
return "End of file";
case AVERROR_EXIT:
return "Immediate exit was requested; the called function should not be restarted";
case AVERROR_FILTER_NOT_FOUND:
return "Filter not found";
case AVERROR_INVALIDDATA:
return "Invalid data found when processing input";
case AVERROR_MUXER_NOT_FOUND:
return "Muxer not found";
case AVERROR_OPTION_NOT_FOUND:
return "Option not found";
case AVERROR_PATCHWELCOME:
return "Not yet implemented in FFmpeg, patches welcome";
case AVERROR_PROTOCOL_NOT_FOUND:
return "Protocol not found";
case AVERROR_STREAM_NOT_FOUND:
return "Stream not found";
default:
break;
}
#else
switch(err) { switch(err) {
case AVERROR_NUMEXPECTED: case AVERROR_NUMEXPECTED:
return "Incorrect filename syntax"; return "Incorrect filename syntax";
...@@ -838,6 +890,8 @@ static const char * icvFFMPEGErrStr(int err) ...@@ -838,6 +890,8 @@ static const char * icvFFMPEGErrStr(int err)
default: default:
break; break;
} }
#endif
return "Unspecified error"; return "Unspecified error";
} }
...@@ -918,7 +972,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, ...@@ -918,7 +972,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
#endif #endif
#if LIBAVFORMAT_BUILD > 4621 #if LIBAVFORMAT_BUILD > 4621
c->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO); c->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
#else #else
c->codec_id = oc->oformat->video_codec; c->codec_id = oc->oformat->video_codec;
#endif #endif
...@@ -930,7 +984,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, ...@@ -930,7 +984,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
//if(codec_tag) c->codec_tag=codec_tag; //if(codec_tag) c->codec_tag=codec_tag;
codec = avcodec_find_encoder(c->codec_id); codec = avcodec_find_encoder(c->codec_id);
c->codec_type = CODEC_TYPE_VIDEO; c->codec_type = AVMEDIA_TYPE_VIDEO;
/* put sample parameters */ /* put sample parameters */
c->bit_rate = bitrate; c->bit_rate = bitrate;
...@@ -1015,6 +1069,10 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_ ...@@ -1015,6 +1069,10 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
AVPacket pkt; AVPacket pkt;
av_init_packet(&pkt); av_init_packet(&pkt);
#ifndef PKT_FLAG_KEY
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
#endif
pkt.flags |= PKT_FLAG_KEY; pkt.flags |= PKT_FLAG_KEY;
pkt.stream_index= video_st->index; pkt.stream_index= video_st->index;
pkt.data= (uint8_t *)picture; pkt.data= (uint8_t *)picture;
...@@ -1237,7 +1295,13 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, ...@@ -1237,7 +1295,13 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
av_register_all (); av_register_all ();
/* auto detect the output format from the name and fourcc code. */ /* auto detect the output format from the name and fourcc code. */
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 4, 0)
fmt = av_guess_format(NULL, filename, NULL);
#else
fmt = guess_format(NULL, filename, NULL); fmt = guess_format(NULL, filename, NULL);
#endif
if (!fmt) if (!fmt)
return false; return false;
...@@ -1260,7 +1324,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, ...@@ -1260,7 +1324,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
#endif #endif
// alloc memory for context // alloc memory for context
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 4, 0)
oc = avformat_alloc_context();
#else
oc = av_alloc_format_context(); oc = av_alloc_format_context();
#endif
assert (oc); assert (oc);
/* set file name */ /* set file name */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment