Code style refactoring for ffmpeg wrappers
This commit is contained in:
parent
3514042b29
commit
d9e4ad3f50
@ -316,13 +316,13 @@ bool CvCapture_FFMPEG::reopen()
|
||||
}
|
||||
|
||||
#ifndef AVSEEK_FLAG_FRAME
|
||||
#define AVSEEK_FLAG_FRAME 0
|
||||
#define AVSEEK_FLAG_FRAME 0
|
||||
#endif
|
||||
#ifndef AVSEEK_FLAG_ANY
|
||||
#define AVSEEK_FLAG_ANY 1
|
||||
#define AVSEEK_FLAG_ANY 1
|
||||
#endif
|
||||
#ifndef SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER
|
||||
#define SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER 25
|
||||
#define SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER 25
|
||||
#endif
|
||||
|
||||
bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
@ -358,9 +358,9 @@ bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
|
||||
avcodec_thread_init(enc, get_number_of_cpus());
|
||||
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
|
||||
#endif
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#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);
|
||||
@ -406,7 +406,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
int flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD;
|
||||
av_seek_frame(ic, video_stream, ts, flags);
|
||||
}
|
||||
exit_func:
|
||||
exit_func:
|
||||
|
||||
if( !valid )
|
||||
close();
|
||||
@ -452,15 +452,15 @@ bool CvCapture_FFMPEG::grabFrame()
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
|
||||
#else
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_decode_video(video_st->codec,
|
||||
picture, &got_picture,
|
||||
packet.data, packet.size);
|
||||
#else
|
||||
#else
|
||||
avcodec_decode_video(&video_st->codec,
|
||||
picture, &got_picture,
|
||||
packet.data, packet.size);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (got_picture) {
|
||||
@ -959,9 +959,9 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
|
||||
#ifndef PKT_FLAG_KEY
|
||||
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
|
||||
#endif
|
||||
#ifndef PKT_FLAG_KEY
|
||||
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
|
||||
#endif
|
||||
|
||||
pkt.flags |= PKT_FLAG_KEY;
|
||||
pkt.stream_index= video_st->index;
|
||||
@ -1067,7 +1067,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
|
||||
}
|
||||
|
||||
// check if buffer sizes match, i.e. image has expected format (size, channels, bitdepth, alignment)
|
||||
/*#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(37<<8)+0)
|
||||
/*#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(37<<8)+0)
|
||||
assert (image->imageSize == avpicture_get_size( (PixelFormat)input_pix_fmt, image->width, image->height ));
|
||||
#else
|
||||
assert (image->imageSize == avpicture_get_size( input_pix_fmt, image->width, image->height ));
|
||||
@ -1186,12 +1186,12 @@ void CvVideoWriter_FFMPEG::close()
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a video writer object that uses FFMPEG
|
||||
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
/// Create a video writer object that uses FFMPEG
|
||||
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
double fps, int width, int height, bool is_color )
|
||||
{
|
||||
{
|
||||
CodecID codec_id = CODEC_ID_NONE;
|
||||
int err, codec_pix_fmt, bitrate_scale = 64;
|
||||
|
||||
@ -1361,12 +1361,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
av_write_header( oc );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
{
|
||||
CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
{
|
||||
CvCapture_FFMPEG* capture = (CvCapture_FFMPEG*)malloc(sizeof(*capture));
|
||||
capture->init();
|
||||
if( capture->open( filename ))
|
||||
@ -1374,44 +1374,44 @@ CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
capture->close();
|
||||
free(capture);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture)
|
||||
{
|
||||
void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture)
|
||||
{
|
||||
if( capture && *capture )
|
||||
{
|
||||
(*capture)->close();
|
||||
free(*capture);
|
||||
*capture = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value)
|
||||
{
|
||||
int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value)
|
||||
{
|
||||
return capture->setProperty(prop_id, value);
|
||||
}
|
||||
}
|
||||
|
||||
double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id)
|
||||
{
|
||||
double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id)
|
||||
{
|
||||
return capture->getProperty(prop_id);
|
||||
}
|
||||
}
|
||||
|
||||
int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture)
|
||||
{
|
||||
int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture)
|
||||
{
|
||||
return capture->grabFrame();
|
||||
}
|
||||
}
|
||||
|
||||
int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn)
|
||||
{
|
||||
int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn)
|
||||
{
|
||||
return capture->retrieveFrame(0, data, step, width, height, cn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps,
|
||||
CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps,
|
||||
int width, int height, int isColor )
|
||||
{
|
||||
{
|
||||
CvVideoWriter_FFMPEG* writer = (CvVideoWriter_FFMPEG*)malloc(sizeof(*writer));
|
||||
writer->init();
|
||||
if( writer->open( filename, fourcc, fps, width, height, isColor != 0 ))
|
||||
@ -1419,24 +1419,24 @@ CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int four
|
||||
writer->close();
|
||||
free(writer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer )
|
||||
{
|
||||
void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer )
|
||||
{
|
||||
if( writer && *writer )
|
||||
{
|
||||
(*writer)->close();
|
||||
free(*writer);
|
||||
*writer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer,
|
||||
int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer,
|
||||
const unsigned char* data, int step,
|
||||
int width, int height, int cn, int origin)
|
||||
{
|
||||
{
|
||||
return writer->writeFrame(data, step, width, height, cn, origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,9 +255,9 @@ void CvCapture_FFMPEG::init()
|
||||
memset( &frame, 0, sizeof(frame) );
|
||||
filename = 0;
|
||||
packet.data = NULL;
|
||||
#if defined(HAVE_FFMPEG_SWSCALE)
|
||||
#if defined(HAVE_FFMPEG_SWSCALE)
|
||||
img_convert_ctx = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
avcodec = 0;
|
||||
frame_number = 0;
|
||||
@ -272,23 +272,23 @@ void CvCapture_FFMPEG::close()
|
||||
|
||||
if( video_st )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_close( video_st->codec );
|
||||
|
||||
#else
|
||||
#else
|
||||
avcodec_close( &(video_st->codec) );
|
||||
|
||||
#endif
|
||||
#endif
|
||||
video_st = NULL;
|
||||
}
|
||||
|
||||
if( ic )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
|
||||
av_close_input_file(ic);
|
||||
#else
|
||||
#else
|
||||
avformat_close_input(&ic);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ic = NULL;
|
||||
}
|
||||
@ -363,10 +363,10 @@ bool CvCapture_FFMPEG::reopen()
|
||||
}
|
||||
|
||||
#ifndef AVSEEK_FLAG_FRAME
|
||||
#define AVSEEK_FLAG_FRAME 0
|
||||
#define AVSEEK_FLAG_FRAME 0
|
||||
#endif
|
||||
#ifndef AVSEEK_FLAG_ANY
|
||||
#define AVSEEK_FLAG_ANY 1
|
||||
#define AVSEEK_FLAG_ANY 1
|
||||
#endif
|
||||
|
||||
bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
@ -376,9 +376,9 @@ bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
|
||||
close();
|
||||
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
|
||||
avformat_network_init();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* register all codecs, demux and protocols */
|
||||
av_register_all();
|
||||
@ -391,45 +391,45 @@ bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
goto exit_func;
|
||||
}
|
||||
err =
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 6, 0)
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 6, 0)
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
|
||||
avformat_find_stream_info(ic);
|
||||
#else
|
||||
#else
|
||||
avformat_find_stream_info(ic, NULL);
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
#else
|
||||
av_find_stream_info(ic);
|
||||
#endif
|
||||
#endif
|
||||
if (err < 0) {
|
||||
CV_WARN("Could not find codec parameters");
|
||||
goto exit_func;
|
||||
}
|
||||
for(i = 0; i < ic->nb_streams; i++)
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext *enc = ic->streams[i]->codec;
|
||||
#else
|
||||
#else
|
||||
AVCodecContext *enc = &ic->streams[i]->codec;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef FF_API_THREAD_INIT
|
||||
#ifdef FF_API_THREAD_INIT
|
||||
avcodec_thread_init(enc, get_number_of_cpus());
|
||||
#else
|
||||
#else
|
||||
enc->thread_count = get_number_of_cpus();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
|
||||
#endif
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#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);
|
||||
if (!codec ||
|
||||
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
|
||||
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
|
||||
avcodec_open2(enc, codec, NULL)
|
||||
#else
|
||||
#else
|
||||
avcodec_open(enc, codec)
|
||||
#endif
|
||||
#endif
|
||||
< 0) goto exit_func;
|
||||
|
||||
video_stream = i;
|
||||
@ -471,7 +471,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
|
||||
int flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD;
|
||||
av_seek_frame(ic, video_stream, ts, flags);
|
||||
}*/
|
||||
exit_func:
|
||||
exit_func:
|
||||
|
||||
if( !valid )
|
||||
close();
|
||||
@ -906,9 +906,9 @@ void CvVideoWriter_FFMPEG::init()
|
||||
video_st = 0;
|
||||
input_pix_fmt = 0;
|
||||
memset(&temp_image, 0, sizeof(temp_image));
|
||||
#if defined(HAVE_FFMPEG_SWSCALE)
|
||||
#if defined(HAVE_FFMPEG_SWSCALE)
|
||||
img_convert_ctx = 0;
|
||||
#endif
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
@ -952,28 +952,28 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
|
||||
int frame_rate, frame_rate_base;
|
||||
AVCodec *codec;
|
||||
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
|
||||
st = avformat_new_stream(oc, 0);
|
||||
#else
|
||||
#else
|
||||
st = av_new_stream(oc, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (!st) {
|
||||
CV_WARN("Could not allocate stream");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
c = st->codec;
|
||||
#else
|
||||
#else
|
||||
c = &(st->codec);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4621
|
||||
#if LIBAVFORMAT_BUILD > 4621
|
||||
c->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
|
||||
#else
|
||||
#else
|
||||
c->codec_id = oc->oformat->video_codec;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(codec_id != CODEC_ID_NONE){
|
||||
c->codec_id = codec_id;
|
||||
@ -1001,7 +1001,7 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
|
||||
frame_rate_base*=10;
|
||||
frame_rate=(int)(fps*frame_rate_base + 0.5);
|
||||
}
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
c->time_base.den = frame_rate;
|
||||
c->time_base.num = frame_rate_base;
|
||||
/* adjust time base for supported framerates */
|
||||
@ -1021,10 +1021,10 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
|
||||
c->time_base.den= best->num;
|
||||
c->time_base.num= best->den;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
c->frame_rate = frame_rate;
|
||||
c->frame_rate_base = frame_rate_base;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
|
||||
c->pix_fmt = (PixelFormat) pixel_format;
|
||||
@ -1039,24 +1039,24 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
|
||||
/* avoid FFMPEG warning 'clipping 1 dct coefficients...' */
|
||||
c->mb_decision=2;
|
||||
}
|
||||
#if LIBAVCODEC_VERSION_INT>0x000409
|
||||
#if LIBAVCODEC_VERSION_INT>0x000409
|
||||
// some formats want stream headers to be seperate
|
||||
if(oc->oformat->flags & AVFMT_GLOBALHEADER)
|
||||
{
|
||||
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture )
|
||||
{
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext * c = video_st->codec;
|
||||
#else
|
||||
#else
|
||||
AVCodecContext * c = &(video_st->codec);
|
||||
#endif
|
||||
#endif
|
||||
int out_size;
|
||||
int ret;
|
||||
|
||||
@ -1066,9 +1066,9 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
|
||||
#ifndef PKT_FLAG_KEY
|
||||
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
|
||||
#endif
|
||||
#ifndef PKT_FLAG_KEY
|
||||
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
|
||||
#endif
|
||||
|
||||
pkt.flags |= PKT_FLAG_KEY;
|
||||
pkt.stream_index= video_st->index;
|
||||
@ -1084,12 +1084,12 @@ int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
#if LIBAVFORMAT_BUILD > 4752
|
||||
if(c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE)
|
||||
pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
|
||||
#else
|
||||
#else
|
||||
pkt.pts = c->coded_frame->pts;
|
||||
#endif
|
||||
#endif
|
||||
if(c->coded_frame->key_frame)
|
||||
pkt.flags |= PKT_FLAG_KEY;
|
||||
pkt.stream_index= video_st->index;
|
||||
@ -1113,13 +1113,13 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
|
||||
bool ret = false;
|
||||
|
||||
// typecast from opaque data type to implemented struct
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
AVCodecContext *c = video_st->codec;
|
||||
#else
|
||||
#else
|
||||
AVCodecContext *c = &(video_st->codec);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIBAVFORMAT_BUILD < 5231
|
||||
#if LIBAVFORMAT_BUILD < 5231
|
||||
// It is not needed in the latest versions of the ffmpeg
|
||||
if( c->codec_id == CODEC_ID_RAWVIDEO && origin != 1 )
|
||||
{
|
||||
@ -1136,7 +1136,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
|
||||
data = temp_image.data;
|
||||
step = temp_image.step;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
if( width*cn != step )
|
||||
{
|
||||
if( !temp_image.data )
|
||||
@ -1156,7 +1156,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int
|
||||
data = temp_image.data;
|
||||
step = temp_image.step;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// check parameters
|
||||
if (input_pix_fmt == PIX_FMT_BGR24) {
|
||||
@ -1235,11 +1235,11 @@ void CvVideoWriter_FFMPEG::close()
|
||||
av_write_trailer(oc);
|
||||
|
||||
// free pictures
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
if( video_st->codec->pix_fmt != input_pix_fmt){
|
||||
#else
|
||||
#else
|
||||
if( video_st->codec.pix_fmt != input_pix_fmt){
|
||||
#endif
|
||||
#endif
|
||||
if(picture->data[0])
|
||||
free(picture->data[0]);
|
||||
picture->data[0] = 0;
|
||||
@ -1251,11 +1251,11 @@ void CvVideoWriter_FFMPEG::close()
|
||||
}
|
||||
|
||||
/* close codec */
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
avcodec_close(video_st->codec);
|
||||
#else
|
||||
#else
|
||||
avcodec_close(&(video_st->codec));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
av_free(outbuf);
|
||||
|
||||
@ -1268,15 +1268,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)
|
||||
#if LIBAVCODEC_VERSION_INT < ((52<<16)+(123<<8)+0)
|
||||
#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(49<<8)+0)
|
||||
url_fclose(oc->pb);
|
||||
#else
|
||||
#else
|
||||
url_fclose(&oc->pb);
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
#else
|
||||
avio_close(oc->pb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -1290,12 +1290,12 @@ void CvVideoWriter_FFMPEG::close()
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a video writer object that uses FFMPEG
|
||||
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
/// Create a video writer object that uses FFMPEG
|
||||
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
double fps, int width, int height, bool is_color )
|
||||
{
|
||||
{
|
||||
CodecID codec_id = CODEC_ID_NONE;
|
||||
int err, codec_pix_fmt, bitrate_scale=64;
|
||||
|
||||
@ -1311,11 +1311,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
|
||||
/* auto detect the output format from the name and fourcc code. */
|
||||
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
fmt = av_guess_format(NULL, filename, NULL);
|
||||
#else
|
||||
#else
|
||||
fmt = guess_format(NULL, filename, NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (!fmt)
|
||||
return false;
|
||||
@ -1329,21 +1329,21 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
}
|
||||
|
||||
/* Lookup codec_id for given fourcc */
|
||||
#if LIBAVCODEC_VERSION_INT<((51<<16)+(49<<8)+0)
|
||||
#if LIBAVCODEC_VERSION_INT<((51<<16)+(49<<8)+0)
|
||||
if( (codec_id = codec_get_bmp_id( fourcc )) == CODEC_ID_NONE )
|
||||
return false;
|
||||
#else
|
||||
#else
|
||||
const struct AVCodecTag * tags[] = { codec_bmp_tags, NULL};
|
||||
if( (codec_id = av_codec_get_id(tags, fourcc)) == CODEC_ID_NONE )
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// alloc memory for context
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
oc = avformat_alloc_context();
|
||||
#else
|
||||
#else
|
||||
oc = av_alloc_format_context();
|
||||
#endif
|
||||
#endif
|
||||
assert (oc);
|
||||
|
||||
/* set file name */
|
||||
@ -1355,12 +1355,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
|
||||
// set a few optimal pixel formats for lossless codecs of interest..
|
||||
switch (codec_id) {
|
||||
#if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
|
||||
#if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
|
||||
case CODEC_ID_JPEGLS:
|
||||
// BGR24 or GRAY8 depending on is_color...
|
||||
codec_pix_fmt = input_pix_fmt;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
case CODEC_ID_HUFFYUV:
|
||||
codec_pix_fmt = PIX_FMT_YUV422P;
|
||||
break;
|
||||
@ -1388,19 +1388,19 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
|
||||
/* set the output parameters (must be done even if no
|
||||
parameters). */
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
if (av_set_parameters(oc, NULL) < 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if FF_API_DUMP_FORMAT
|
||||
#if 0
|
||||
#if FF_API_DUMP_FORMAT
|
||||
dump_format(oc, 0, filename, 1);
|
||||
#else
|
||||
#else
|
||||
av_dump_format(oc, 0, filename, 1);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* now that all the parameters are set, we can open the audio and
|
||||
video codecs and allocate the necessary encode buffers */
|
||||
@ -1411,11 +1411,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
AVCodec *codec;
|
||||
AVCodecContext *c;
|
||||
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
#if LIBAVFORMAT_BUILD > 4628
|
||||
c = (video_st->codec);
|
||||
#else
|
||||
#else
|
||||
c = &(video_st->codec);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
c->codec_tag = fourcc;
|
||||
/* find the video encoder */
|
||||
@ -1428,11 +1428,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
|
||||
/* open the codec */
|
||||
if ((err=
|
||||
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
|
||||
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
|
||||
avcodec_open2(c, codec, NULL)
|
||||
#else
|
||||
#else
|
||||
avcodec_open(c, codec)
|
||||
#endif
|
||||
#endif
|
||||
) < 0) {
|
||||
char errtext[256];
|
||||
sprintf(errtext, "Could not open codec '%s': %s", codec->name, icvFFMPEGErrStr(err));
|
||||
@ -1470,11 +1470,11 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
|
||||
/* open the output file, if needed */
|
||||
if (!(fmt->flags & AVFMT_NOFILE)) {
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
|
||||
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0)
|
||||
#else
|
||||
#else
|
||||
if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0)
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1490,12 +1490,12 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
|
||||
}
|
||||
ok = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
{
|
||||
CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
{
|
||||
CvCapture_FFMPEG* capture = (CvCapture_FFMPEG*)malloc(sizeof(*capture));
|
||||
capture->init();
|
||||
if( capture->open( filename ))
|
||||
@ -1503,44 +1503,44 @@ CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename )
|
||||
capture->close();
|
||||
free(capture);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture)
|
||||
{
|
||||
void cvReleaseCapture_FFMPEG(CvCapture_FFMPEG** capture)
|
||||
{
|
||||
if( capture && *capture )
|
||||
{
|
||||
(*capture)->close();
|
||||
free(*capture);
|
||||
*capture = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value)
|
||||
{
|
||||
int cvSetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id, double value)
|
||||
{
|
||||
return capture->setProperty(prop_id, value);
|
||||
}
|
||||
}
|
||||
|
||||
double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id)
|
||||
{
|
||||
double cvGetCaptureProperty_FFMPEG(CvCapture_FFMPEG* capture, int prop_id)
|
||||
{
|
||||
return capture->getProperty(prop_id);
|
||||
}
|
||||
}
|
||||
|
||||
int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture)
|
||||
{
|
||||
int cvGrabFrame_FFMPEG(CvCapture_FFMPEG* capture)
|
||||
{
|
||||
return capture->grabFrame();
|
||||
}
|
||||
}
|
||||
|
||||
int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn)
|
||||
{
|
||||
int cvRetrieveFrame_FFMPEG(CvCapture_FFMPEG* capture, unsigned char** data, int* step, int* width, int* height, int* cn)
|
||||
{
|
||||
return capture->retrieveFrame(0, data, step, width, height, cn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps,
|
||||
CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int fourcc, double fps,
|
||||
int width, int height, int isColor )
|
||||
{
|
||||
{
|
||||
CvVideoWriter_FFMPEG* writer = (CvVideoWriter_FFMPEG*)malloc(sizeof(*writer));
|
||||
writer->init();
|
||||
if( writer->open( filename, fourcc, fps, width, height, isColor != 0 ))
|
||||
@ -1548,24 +1548,24 @@ CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int four
|
||||
writer->close();
|
||||
free(writer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer )
|
||||
{
|
||||
void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer )
|
||||
{
|
||||
if( writer && *writer )
|
||||
{
|
||||
(*writer)->close();
|
||||
free(*writer);
|
||||
*writer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer,
|
||||
int cvWriteFrame_FFMPEG( CvVideoWriter_FFMPEG* writer,
|
||||
const unsigned char* data, int step,
|
||||
int width, int height, int cn, int origin)
|
||||
{
|
||||
{
|
||||
return writer->writeFrame(data, step, width, height, cn, origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user