ports/136390: Compilation Problem highgui Opencv
Joerg Ruppe-Tanner
joerg.ruppe.tanner at gmail.com
Mon Jul 6 20:20:03 UTC 2009
>Number: 136390
>Category: ports
>Synopsis: Compilation Problem highgui Opencv
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon Jul 06 20:20:02 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Joerg Ruppe-Tanner
>Release: FreeBSD7.2-RELEASE-p2
>Organization:
jrtnet.ch
>Environment:
FreeBSD neptun.jrtnet.ch 7.2-RELEASE-p2 FreeBSD 7.2-RELEASE-p2 #0: Wed Jun 24 00:14:35 UTC 2009 root at amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
In file included from /usr/local/include/ffmpeg/avformat.h:40,^M
from cvcap_ffmpeg.cpp:47:^M
/usr/local/include/libavcodec/avcodec.h:2353: warning: 'ImgReSampleContext' is deprecated (declared at /usr/l
ocal/include/libavcodec/avcodec.h:2347)^M
/usr/local/include/libavcodec/avcodec.h:2363: warning: 'ImgReSampleContext' is deprecated (declared at /usr/l
ocal/include/libavcodec/avcodec.h:2347)^M
cvcap_ffmpeg.cpp: In function 'int icvOpenAVI_FFMPEG(CvCaptureAVI_FFMPEG*, const char*)':^M
cvcap_ffmpeg.cpp:128: warning: comparison between signed and unsigned integer expressions^M
cvcap_ffmpeg.cpp: In function 'void cvReleaseVideoWriter(CvVideoWriter**)':^M
cvcap_ffmpeg.cpp:797: warning: comparison between signed and unsigned integer expressions^M
cvcap_ffmpeg.cpp:804: error: cannot convert 'ByteIOContext**' to 'ByteIOContext*' for argument '1' to 'int ur
l_fclose(ByteIOContext*)'^M
gmake[3]: *** [cvcap_ffmpeg.lo] Error 1^M
gmake[3]: Leaving directory `/usr/ports/graphics/opencv/work/opencv-1.0.0/otherlibs/highgui'^M
gmake[2]: *** [all-recursive] Error 1^M
gmake[2]: Leaving directory `/usr/ports/graphics/opencv/work/opencv-1.0.0/otherlibs'^M
gmake[1]: *** [all-recursive] Error 1^M
gmake[1]: Leaving directory `/usr/ports/graphics/opencv/work/opencv-1.0.0'^M
gmake: *** [all] Error 2^M
*** Error code 1^M
^M
Stop in /usr/ports/graphics/opencv.^M
*** Error code 1^M
^M
Stop in /usr/ports/graphics/opencv.^M
You have new mail in /var/mail/root^M
(^[[1m08:02:29 root at neptun </usr/ports/graphics/opencv>^[[m) 0 # cd /usr/ports/graphics/opencv/work/opencv-1.
0.0/otherlibs/highgui^M
>How-To-Repeat:
>Fix:
see attachment, replacing cvcap_ffmpeg.cpp file
Patch attached with submission follows:
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# cvcap_ffmpeg.cpp
# diff-u-cvcap_ffmpeg.cpp-cvcap_ffmpeg.cpp.orig.txt
#
echo x - cvcap_ffmpeg.cpp
sed 's/^X//' >cvcap_ffmpeg.cpp << 'b7360fd8d1398db708fe32e88508178a'
X/*M///////////////////////////////////////////////////////////////////////////////////////
X//
X// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
X//
X// By downloading, copying, installing or using the software you agree to this license.
X// If you do not agree to this license, do not download, install,
X// copy or use the software.
X//
X//
X// Intel License Agreement
X// For Open Source Computer Vision Library
X//
X// Copyright (C) 2000, Intel Corporation, all rights reserved.
X// Third party copyrights are property of their respective owners.
X//
X// Redistribution and use in source and binary forms, with or without modification,
X// are permitted provided that the following conditions are met:
X//
X// * Redistribution's of source code must retain the above copyright notice,
X// this list of conditions and the following disclaimer.
X//
X// * Redistribution's in binary form must reproduce the above copyright notice,
X// this list of conditions and the following disclaimer in the documentation
X// and/or other materials provided with the distribution.
X//
X// * The name of Intel Corporation may not be used to endorse or promote products
X// derived from this software without specific prior written permission.
X//
X// This software is provided by the copyright holders and contributors "as is" and
X// any express or implied warranties, including, but not limited to, the implied
X// warranties of merchantability and fitness for a particular purpose are disclaimed.
X// In no event shall the Intel Corporation or contributors be liable for any direct,
X// indirect, incidental, special, exemplary, or consequential damages
X// (including, but not limited to, procurement of substitute goods or services;
X// loss of use, data, or profits; or business interruption) however caused
X// and on any theory of liability, whether in contract, strict liability,
X// or tort (including negligence or otherwise) arising in any way out of
X// the use of this software, even if advised of the possibility of such damage.
X//
X//M*/
X
X
X#define INT64_C
X#define __STDC_CONSTANT_MACROS
X
X#include "_highgui.h"
X
X
Xextern "C" {
X#include <ffmpeg/avformat.h>
X}
X
X#ifdef NDEBUG
X#define CV_WARN(message)
X#else
X#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__)
X#endif
X
Xtypedef struct CvCaptureAVI_FFMPEG
X{
X CvCaptureVTable * vtable;
X
X AVFormatContext * ic;
X int video_stream;
X AVStream * video_st;
X AVFrame * picture;
X int64_t picture_pts;
X AVFrame rgb_picture;
X
X IplImage frame;
X} CvCaptureAVI_FFMPEG;
X
Xstatic void icvCloseAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
X{
X //cvFree( (void**)&(capture->entries) );
X
X if( capture->picture )
X av_free(capture->picture);
X
X if( capture->video_st )
X {
X#if LIBAVFORMAT_BUILD > 4628
X avcodec_close( capture->video_st->codec );
X#else
X avcodec_close( &capture->video_st->codec );
X#endif
X capture->video_st = NULL;
X }
X
X if( capture->ic )
X {
X av_close_input_file(capture->ic);
X capture->ic = NULL;
X }
X
X if( capture->rgb_picture.data[0] )
X cvFree( &capture->rgb_picture.data[0] );
X
X memset( &capture->frame, 0, sizeof(capture->frame));
X}
X
X
Xstatic int icvOpenAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture, const char* filename )
X{
X int err, valid = 0, video_index = -1, i;
X AVFormatContext *ic;
X
X capture->ic = NULL;
X capture->video_stream = -1;
X capture->video_st = NULL;
X /* register all codecs, demux and protocols */
X av_register_all();
X
X err = av_open_input_file(&ic, filename, NULL, 0, NULL);
X if (err < 0) {
X CV_WARN("Error opening file");
X goto exit_func;
X }
X capture->ic = ic;
X err = av_find_stream_info(ic);
X if (err < 0) {
X CV_WARN("Could not find codec parameters");
X goto exit_func;
X }
X for(i = 0; i < ic->nb_streams; i++) {
X#if LIBAVFORMAT_BUILD > 4628
X AVCodecContext *enc = ic->streams[i]->codec;
X#else
X AVCodecContext *enc = &ic->streams[i]->codec;
X#endif
X AVCodec *codec;
X if( CODEC_TYPE_VIDEO == enc->codec_type && video_index < 0) {
X video_index = i;
X codec = avcodec_find_decoder(enc->codec_id);
X if (!codec ||
X avcodec_open(enc, codec) < 0)
X goto exit_func;
X capture->video_stream = i;
X capture->video_st = ic->streams[i];
X capture->picture = avcodec_alloc_frame();
X
X capture->rgb_picture.data[0] = (uchar*)cvAlloc(
X avpicture_get_size( PIX_FMT_BGR24,
X enc->width, enc->height ));
X avpicture_fill( (AVPicture*)&capture->rgb_picture, capture->rgb_picture.data[0],
X PIX_FMT_BGR24, enc->width, enc->height );
X
X cvInitImageHeader( &capture->frame, cvSize( enc->width,
X enc->height ), 8, 3, 0, 4 );
X cvSetData( &capture->frame, capture->rgb_picture.data[0],
X capture->rgb_picture.linesize[0] );
X break;
X }
X }
X
X
X if(video_index >= 0)
X valid = 1;
X
Xexit_func:
X
X if( !valid )
X icvCloseAVI_FFMPEG( capture );
X
X return valid;
X}
X
X
Xstatic int icvGrabFrameAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
X{
X int valid=0;
X static bool bFirstTime = true;
X static AVPacket pkt;
X int got_picture;
X
X // First time we're called, set packet.data to NULL to indicate it
X // doesn't have to be freed
X if (bFirstTime) {
X bFirstTime = false;
X pkt.data = NULL;
X }
X
X if( !capture || !capture->ic || !capture->video_st )
X return 0;
X
X // free last packet if exist
X if (pkt.data != NULL) {
X av_free_packet (&pkt);
X }
X
X // get the next frame
X while ((0 == valid) && (av_read_frame(capture->ic, &pkt) >= 0)) {
X if( pkt.stream_index != capture->video_stream ) continue;
X
X#if LIBAVFORMAT_BUILD > 4628
X avcodec_decode_video(capture->video_st->codec,
X capture->picture, &got_picture,
X pkt.data, pkt.size);
X#else
X avcodec_decode_video(&capture->video_st->codec,
X capture->picture, &got_picture,
X pkt.data, pkt.size);
X#endif
X
X if (got_picture) {
X // we have a new picture, so memorize it
X capture->picture_pts = pkt.pts;
X valid = 1;
X }
X }
X
X // return if we have a new picture or not
X return valid;
X}
X
X
Xstatic const IplImage* icvRetrieveFrameAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
X{
X if( !capture || !capture->video_st || !capture->picture->data[0] )
X return 0;
X#if LIBAVFORMAT_BUILD > 4628
X img_convert( (AVPicture*)&capture->rgb_picture, PIX_FMT_BGR24,
X (AVPicture*)capture->picture,
X capture->video_st->codec->pix_fmt,
X capture->video_st->codec->width,
X capture->video_st->codec->height );
X#else
X img_convert( (AVPicture*)&capture->rgb_picture, PIX_FMT_BGR24,
X (AVPicture*)capture->picture,
X capture->video_st->codec.pix_fmt,
X capture->video_st->codec.width,
X capture->video_st->codec.height );
X#endif
X return &capture->frame;
X}
X
X
Xstatic int icvSetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture,
X int property_id, double value );
X
Xstatic double icvGetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture, int property_id )
X{
X if( !capture || !capture->video_st || !capture->picture->data[0] )
X return 0;
X
X int64_t timestamp;
X timestamp = capture->picture_pts;
X
X switch( property_id )
X {
X case CV_CAP_PROP_POS_MSEC:
X if(capture->ic->start_time != static_cast<double>(AV_NOPTS_VALUE))
X return (double)(timestamp - capture->ic->start_time)*1000/(double)AV_TIME_BASE;
X break;
X case CV_CAP_PROP_POS_FRAMES:
X if(capture->video_st->cur_dts != static_cast<double>(AV_NOPTS_VALUE))
X return (double)capture->video_st->cur_dts-1;
X break;
X case CV_CAP_PROP_POS_AVI_RATIO:
X if(capture->ic->start_time != static_cast<double>(AV_NOPTS_VALUE) && capture->ic->duration != static_cast<double>(AV_NOPTS_VALUE))
X return (double)(timestamp-capture->ic->start_time)/(double)capture->ic->duration;
X break;
X case CV_CAP_PROP_FRAME_WIDTH:
X return capture->frame.width;
X break;
X case CV_CAP_PROP_FRAME_HEIGHT:
X return capture->frame.height;
X break;
X case CV_CAP_PROP_FPS:
X#if LIBAVCODEC_BUILD > 4753
X return av_q2d (capture->video_st->r_frame_rate);
X#else
X return (double)capture->video_st->codec.frame_rate
X / (double)capture->video_st->codec.frame_rate_base;
X#endif
X break;
X case CV_CAP_PROP_FOURCC:
X#if LIBAVFORMAT_BUILD > 4628
X return (double)capture->video_st->codec->codec_tag;
X#else
X return (double)capture->video_st->codec.codec_tag;
X#endif
X break;
X }
X return 0;
X}
X
X
Xstatic int icvSetPropertyAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture,
X int property_id, double value )
X{
X if( !capture || !capture->video_st || !capture->picture->data[0] )
X return 0;
X switch( property_id )
X {
X//#if 0
X case CV_CAP_PROP_POS_MSEC:
X case CV_CAP_PROP_POS_FRAMES:
X case CV_CAP_PROP_POS_AVI_RATIO:
X {
X int64_t timestamp = AV_NOPTS_VALUE;
X switch( property_id )
X {
X case CV_CAP_PROP_POS_FRAMES:
X if(capture->ic->start_time != AV_NOPTS_VALUE) {
X#if LIBAVCODEC_BUILD > 4753
X value *= 1 / av_q2d (capture->video_st->r_frame_rate);
X#else
X value *= (double)capture->video_st->codec.frame_rate_base
X / (double)capture->video_st->codec.frame_rate;
X timestamp = capture->ic->start_time+(int64_t)(value*AV_TIME_BASE);
X#endif
X }
X break;
X case CV_CAP_PROP_POS_MSEC:
X if(capture->ic->start_time != AV_NOPTS_VALUE)
X timestamp = capture->ic->start_time+(int64_t)(value*AV_TIME_BASE/1000);
X break;
X case CV_CAP_PROP_POS_AVI_RATIO:
X if(capture->ic->start_time != AV_NOPTS_VALUE && capture->ic->duration != AV_NOPTS_VALUE)
X timestamp = capture->ic->start_time+(int64_t)(value*capture->ic->duration);
X break;
X }
X if(timestamp != AV_NOPTS_VALUE) {
X //printf("timestamp=%g\n",(double)timestamp);
X int ret = av_seek_frame(capture->ic, -1, timestamp, 0);
X if (ret < 0) {
X fprintf(stderr, "HIGHGUI ERROR: AVI: could not seek to position %0.3f\n",
X (double)timestamp / AV_TIME_BASE);
X return 0;
X }
X }
X }
X break;
X//#endif
X default:
X return 0;
X }
X
X return 1;
X}
X
Xstatic CvCaptureVTable captureAVI_FFMPEG_vtable =
X{
X 6,
X (CvCaptureCloseFunc)icvCloseAVI_FFMPEG,
X (CvCaptureGrabFrameFunc)icvGrabFrameAVI_FFMPEG,
X (CvCaptureRetrieveFrameFunc)icvRetrieveFrameAVI_FFMPEG,
X (CvCaptureGetPropertyFunc)icvGetPropertyAVI_FFMPEG,
X (CvCaptureSetPropertyFunc)icvSetPropertyAVI_FFMPEG,
X (CvCaptureGetDescriptionFunc)0
X};
X
X
XCvCapture* cvCaptureFromFile_FFMPEG( const char* filename )
X{
X CvCaptureAVI_FFMPEG* capture = 0;
X
X if( filename )
X {
X capture = (CvCaptureAVI_FFMPEG*)cvAlloc( sizeof(*capture));
X memset( capture, 0, sizeof(*capture));
X
X capture->vtable = &captureAVI_FFMPEG_vtable;
X
X if( !icvOpenAVI_FFMPEG( capture, filename ))
X cvReleaseCapture( (CvCapture**)&capture );
X }
X
X return (CvCapture*)capture;
X}
X
X///////////////// FFMPEG CvVideoWriter implementation //////////////////////////
Xtypedef struct CvAVI_FFMPEG_Writer
X{
X AVOutputFormat *fmt;
X AVFormatContext *oc;
X uint8_t * outbuf;
X uint32_t outbuf_size;
X FILE * outfile;
X AVFrame * picture;
X AVFrame * rgb_picture;
X uint8_t * picbuf;
X AVStream * video_st;
X} CvAVI_FFMPEG_Writer;
X
X/**
X * the following function is a modified version of code
X * found in ffmpeg-0.4.9-pre1/output_example.c
X */
Xstatic AVFrame * icv_alloc_picture_FFMPEG(int pix_fmt, int width, int height, bool alloc)
X{
X AVFrame * picture;
X uint8_t * picture_buf;
X int size;
X
X picture = avcodec_alloc_frame();
X if (!picture)
X return NULL;
X size = avpicture_get_size(pix_fmt, width, height);
X if(alloc){
X picture_buf = (uint8_t *) cvAlloc(size);
X if (!picture_buf)
X {
X av_free(picture);
X return NULL;
X }
X avpicture_fill((AVPicture *)picture, picture_buf,
X pix_fmt, width, height);
X }
X else {
X }
X return picture;
X}
X
X/* add a video output stream */
Xstatic AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, int codec_tag, int w, int h, int bitrate, double fps, int pixel_format)
X{
X AVCodecContext *c;
X AVStream *st;
X int codec_id;
X int frame_rate, frame_rate_base;
X AVCodec *codec;
X
X
X st = av_new_stream(oc, 0);
X if (!st) {
X CV_WARN("Could not allocate stream");
X return NULL;
X }
X
X#if LIBAVFORMAT_BUILD > 4628
X c = st->codec;
X#else
X c = &(st->codec);
X#endif
X#if LIBAVFORMAT_BUILD > 4621
X codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
X#else
X codec_id = oc->oformat->video_codec;
X#endif
X
X if(codec_tag) c->codec_tag=codec_tag;
X
X c->codec_id = (CodecID) codec_id;
X codec = avcodec_find_encoder(c->codec_id);
X
X c->codec_type = CODEC_TYPE_VIDEO;
X
X /* put sample parameters */
X c->bit_rate = bitrate;
X
X /* resolution must be a multiple of two */
X c->width = w;
X c->height = h;
X
X /* time base: this is the fundamental unit of time (in seconds) in terms
X of which frame timestamps are represented. for fixed-fps content,
X timebase should be 1/framerate and timestamp increments should be
X identically 1. */
X frame_rate=cvRound(fps);
X frame_rate_base=1;
X while (fabs((double)frame_rate/frame_rate_base) - fps > 0.001){
X frame_rate_base*=10;
X frame_rate=cvRound(fps*frame_rate_base);
X }
X#if LIBAVFORMAT_BUILD > 4752
X c->time_base.den = frame_rate;
X c->time_base.num = frame_rate_base;
X /* adjust time base for supported framerates */
X if(codec && codec->supported_framerates){
X const AVRational *p= codec->supported_framerates;
X AVRational req= (AVRational){frame_rate, frame_rate_base};
X const AVRational *best=NULL;
X AVRational best_error= (AVRational){INT_MAX, 1};
X for(; p->den!=0; p++){
X AVRational error= av_sub_q(req, *p);
X if(error.num <0) error.num *= -1;
X if(av_cmp_q(error, best_error) < 0){
X best_error= error;
X best= p;
X }
X }
X c->time_base.den= best->num;
X c->time_base.num= best->den;
X }
X#else
X c->frame_rate = frame_rate;
X c->frame_rate_base = frame_rate_base;
X#endif
X
X c->gop_size = 12; /* emit one intra frame every twelve frames at most */
X c->pix_fmt = (PixelFormat) pixel_format;
X if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
X /* just for testing, we also add B frames */
X c->max_b_frames = 2;
X }
X if (c->codec_id == CODEC_ID_MPEG1VIDEO){
X /* needed to avoid using macroblocks in which some coeffs overflow
X this doesnt happen with normal video, it just happens here as the
X motion of the chroma plane doesnt match the luma plane */
X c->mb_decision=2;
X }
X // some formats want stream headers to be seperate
X if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name, "mov") || !strcmp(oc->oformat->name, "3gp"))
X c->flags |= CODEC_FLAG_GLOBAL_HEADER;
X
X return st;
X}
X
X/// Create a video writer object that uses FFMPEG
XCV_IMPL CvVideoWriter* cvCreateVideoWriter( const char * filename, int fourcc,
X double fps, CvSize frameSize, int /*is_color*/ )
X{
X CV_FUNCNAME("cvCreateVideoWriter");
X
X CvAVI_FFMPEG_Writer * writer = NULL;
X
X __BEGIN__;
X
X // check arguments
X assert (filename);
X assert (fps > 0);
X assert (frameSize.width > 0 && frameSize.height > 0);
X
X // allocate memory for structure...
X writer = (CvAVI_FFMPEG_Writer *) cvAlloc( sizeof(CvAVI_FFMPEG_Writer));
X memset (writer, 0, sizeof (*writer));
X
X // tell FFMPEG to register codecs
X av_register_all ();
X
X /* auto detect the output format from the name. default is mpeg. */
X writer->fmt = guess_format(NULL, filename, NULL);
X if (!writer->fmt) {
X CV_ERROR( CV_StsUnsupportedFormat, "Could not deduce output format from file extension");
X //writer->fmt = guess_format("mpeg", NULL, NULL);
X }
X
X // alloc memory for context
X writer->oc = av_alloc_format_context();
X assert (writer->oc);
X
X /* set file name */
X writer->oc->oformat = writer->fmt;
X snprintf(writer->oc->filename, sizeof(writer->oc->filename), "%s", filename);
X
X // TODO -- safe to ignore output audio stream?
X writer->video_st = icv_add_video_stream_FFMPEG(writer->oc, fourcc, frameSize.width, frameSize.height, 800000, fps, PIX_FMT_YUV420P);
X
X
X /* set the output parameters (must be done even if no
X parameters). */
X if (av_set_parameters(writer->oc, NULL) < 0) {
X CV_ERROR(CV_StsBadArg, "Invalid output format parameters");
X }
X
X dump_format(writer->oc, 0, filename, 1);
X
X /* now that all the parameters are set, we can open the audio and
X video codecs and allocate the necessary encode buffers */
X if (!writer->video_st){
X CV_ERROR(CV_StsBadArg, "Couldn't open video stream");
X }
X
X AVCodec *codec;
X AVCodecContext *c;
X
X#if LIBAVFORMAT_BUILD > 4628
X c = (writer->video_st->codec);
X#else
X c = &(writer->video_st->codec);
X#endif
X
X /* find the video encoder */
X codec = avcodec_find_encoder(c->codec_id);
X if (!codec) {
X CV_ERROR(CV_StsBadArg, "codec not found");
X }
X
X /* open the codec */
X if (avcodec_open(c, codec) < 0) {
X char errtext[256];
X sprintf(errtext, "Could not open codec '%s'", codec->name);
X CV_ERROR(CV_StsBadArg, errtext);
X }
X
X // printf("Using codec %s\n", codec->name);
X writer->outbuf = NULL;
X
X if (!(writer->oc->oformat->flags & AVFMT_RAWPICTURE)) {
X /* allocate output buffer */
X /* XXX: API change will be done */
X writer->outbuf_size = 200000;
X writer->outbuf = (uint8_t *) malloc(writer->outbuf_size);
X }
X
X bool need_color_convert;
X need_color_convert = c->pix_fmt != PIX_FMT_BGR24;
X
X /* allocate the encoded raw picture */
X writer->picture = icv_alloc_picture_FFMPEG(c->pix_fmt, c->width, c->height, need_color_convert);
X if (!writer->picture) {
X CV_ERROR(CV_StsNoMem, "Could not allocate picture");
X }
X
X /* if the output format is not YUV420P, then a temporary YUV420P
X picture is needed too. It is then converted to the required
X output format */
X writer->rgb_picture = NULL;
X if ( need_color_convert ) {
X writer->rgb_picture = icv_alloc_picture_FFMPEG(PIX_FMT_BGR24, c->width, c->height, false);
X if (!writer->rgb_picture) {
X CV_ERROR(CV_StsNoMem, "Could not allocate picture");
X }
X }
X
X /* open the output file, if needed */
X if (!(writer->fmt->flags & AVFMT_NOFILE)) {
X if (url_fopen(&writer->oc->pb, filename, URL_WRONLY) < 0) {
X CV_ERROR(CV_StsBadArg, "Couldn't open output file for writing");
X }
X }
X
X /* write the stream header, if any */
X av_write_header( writer->oc );
X
X
X __END__;
X
X // return what we got
X return (CvVideoWriter *) writer;
X}
X
Xint icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st, uint8_t * outbuf, uint32_t outbuf_size, AVFrame * picture ){
X CV_FUNCNAME("icv_av_write_frame_FFMPEG");
X
X#if LIBAVFORMAT_BUILD > 4628
X AVCodecContext * c = video_st->codec;
X#else
X AVCodecContext * c = &(video_st->codec);
X#endif
X int out_size;
X int ret;
X
X __BEGIN__;
X
X if (oc->oformat->flags & AVFMT_RAWPICTURE) {
X /* raw video case. The API will change slightly in the near
X futur for that */
X AVPacket pkt;
X av_init_packet(&pkt);
X
X pkt.flags |= PKT_FLAG_KEY;
X pkt.stream_index= video_st->index;
X pkt.data= (uint8_t *)picture;
X pkt.size= sizeof(AVPicture);
X
X ret = av_write_frame(oc, &pkt);
X } else {
X /* encode the image */
X out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
X /* if zero size, it means the image was buffered */
X if (out_size > 0) {
X AVPacket pkt;
X av_init_packet(&pkt);
X#if LIBAVFORMAT_BUILD > 4752
X pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
X#else
X pkt.pts = c->coded_frame->pts;
X#endif
X if(c->coded_frame->key_frame)
X pkt.flags |= PKT_FLAG_KEY;
X pkt.stream_index= video_st->index;
X pkt.data= outbuf;
X pkt.size= out_size;
X
X /* write the compressed frame in the media file */
X ret = av_write_frame(oc, &pkt);
X } else {
X ret = 0;
X }
X }
X if (ret != 0) {
X CV_ERROR(CV_StsError, "Error while writing video frame");
X }
X
X __END__;
X return CV_StsOk;
X}
X
X/// write a frame with FFMPEG
XCV_IMPL int cvWriteFrame( CvVideoWriter * writer, const IplImage * image )
X{
X int ret = 0;
X
X CV_FUNCNAME("cvWriteFrame");
X
X __BEGIN__;
X
X // typecast from opaque data type to implemented struct
X CvAVI_FFMPEG_Writer * mywriter = (CvAVI_FFMPEG_Writer*) writer;
X#if LIBAVFORMAT_BUILD > 4628
X AVCodecContext *c = mywriter->video_st->codec;
X#else
X AVCodecContext *c = &(mywriter->video_st->codec);
X#endif
X // check parameters
X assert ( image );
X assert ( image->nChannels == 3 );
X assert ( image->depth == IPL_DEPTH_8U );
X
X
X // check if buffer sizes match, i.e. image has expected format (size, channels, bitdepth, alignment)
X assert (image->imageSize == avpicture_get_size (PIX_FMT_BGR24, image->width, image->height));
X
X if (c->pix_fmt != PIX_FMT_BGR24 ) {
X assert( mywriter->rgb_picture );
X // let rgb_picture point to the raw data buffer of 'image'
X avpicture_fill((AVPicture *)mywriter->rgb_picture, (uint8_t *) image->imageData,
X PIX_FMT_BGR24, image->width, image->height);
X
X // convert to the color format needed by the codec
X if( img_convert((AVPicture *)mywriter->picture, c->pix_fmt,
X (AVPicture *)mywriter->rgb_picture, PIX_FMT_BGR24,
X image->width, image->height) < 0){
X CV_ERROR(CV_StsUnsupportedFormat, "FFMPEG::img_convert pixel format conversion from BGR24 not handled");
X }
X }
X else{
X avpicture_fill((AVPicture *)mywriter->picture, (uint8_t *) image->imageData,
X PIX_FMT_BGR24, image->width, image->height);
X }
X
X ret = icv_av_write_frame_FFMPEG( mywriter->oc, mywriter->video_st, mywriter->outbuf, mywriter->outbuf_size, mywriter->picture);
X
X __END__;
X return ret;
X}
X
X/// close video output stream and free associated memory
XCV_IMPL void cvReleaseVideoWriter( CvVideoWriter ** writer )
X{
X int i;
X
X // nothing to do if already released
X if ( !(*writer) )
X return;
X
X // release data structures in reverse order
X CvAVI_FFMPEG_Writer * mywriter = (CvAVI_FFMPEG_Writer*)(*writer);
X
X /* no more frame to compress. The codec has a latency of a few
X frames if using B frames, so we get the last frames by
X passing the same picture again */
X // TODO -- do we need to account for latency here?
X
X /* write the trailer, if any */
X av_write_trailer(mywriter->oc);
X
X // free pictures
X#if LIBAVFORMAT_BUILD > 4628
X if( mywriter->video_st->codec->pix_fmt != PIX_FMT_BGR24){
X#else
X if( mywriter->video_st->codec.pix_fmt != PIX_FMT_BGR24){
X#endif
X cvFree(&(mywriter->picture->data[0]));
X }
X av_free(mywriter->picture);
X
X if (mywriter->rgb_picture) {
X av_free(mywriter->rgb_picture);
X }
X
X /* close codec */
X#if LIBAVFORMAT_BUILD > 4628
X avcodec_close(mywriter->video_st->codec);
X#else
X avcodec_close(&(mywriter->video_st->codec));
X#endif
X
X av_free(mywriter->outbuf);
X
X /* free the streams */
X for(i = 0; i < mywriter->oc->nb_streams; i++) {
X av_freep(&mywriter->oc->streams[i]->codec);
X av_freep(&mywriter->oc->streams[i]);
X }
X
X if (!(mywriter->fmt->flags & AVFMT_NOFILE)) {
X /* close the output file */
X#if LIBAVFORMAT_BUILD > 4628
X url_fclose(mywriter->oc->pb);
X#else
X url_fclose(&mywriter->oc->pb);
X#endif
X }
X
X /* free the stream */
X av_free(mywriter->oc);
X
X /* free cvVideoWriter */
X cvFree ( writer );
X
X // mark as released
X (*writer) = 0;
X}
b7360fd8d1398db708fe32e88508178a
echo x - diff-u-cvcap_ffmpeg.cpp-cvcap_ffmpeg.cpp.orig.txt
sed 's/^X//' >diff-u-cvcap_ffmpeg.cpp-cvcap_ffmpeg.cpp.orig.txt << 'ac3c3f639626d030a780fd88b6c45582'
X--- cvcap_ffmpeg.cpp 2009-06-09 17:41:35.000000000 +0200
X+++ cvcap_ffmpeg.cpp.orig 2006-07-25 00:27:39.000000000 +0200
X@@ -39,10 +39,6 @@
X //
X //M*/
X
X-
X-#define INT64_C
X-#define __STDC_CONSTANT_MACROS
X-
X #include "_highgui.h"
X
X
X@@ -293,7 +289,7 @@
X return 0;
X switch( property_id )
X {
X-//#if 0
X+#if 0
X case CV_CAP_PROP_POS_MSEC:
X case CV_CAP_PROP_POS_FRAMES:
X case CV_CAP_PROP_POS_AVI_RATIO:
X@@ -303,13 +299,9 @@
X {
X case CV_CAP_PROP_POS_FRAMES:
X if(capture->ic->start_time != AV_NOPTS_VALUE) {
X-#if LIBAVCODEC_BUILD > 4753
X- value *= 1 / av_q2d (capture->video_st->r_frame_rate);
X-#else
X value *= (double)capture->video_st->codec.frame_rate_base
X / (double)capture->video_st->codec.frame_rate;
X timestamp = capture->ic->start_time+(int64_t)(value*AV_TIME_BASE);
X-#endif
X }
X break;
X case CV_CAP_PROP_POS_MSEC:
X@@ -332,7 +324,7 @@
X }
X }
X break;
X-//#endif
X+#endif
X default:
X return 0;
X }
X@@ -789,11 +781,7 @@
X
X if (!(mywriter->fmt->flags & AVFMT_NOFILE)) {
X /* close the output file */
X-#if LIBAVFORMAT_BUILD > 4628
X- url_fclose(mywriter->oc->pb);
X-#else
X url_fclose(&mywriter->oc->pb);
X-#endif
X }
X
X /* free the stream */
ac3c3f639626d030a780fd88b6c45582
exit
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list