** $Id: trgt_av.cpp,v 1.1.1.1 2005/01/04 01:23:11 darco Exp $
**
** \legal
-** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
**
-** This software and associated documentation
-** are CONFIDENTIAL and PROPRIETARY property of
-** the above-mentioned copyright holder.
+** This package is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License as
+** published by the Free Software Foundation; either version 2 of
+** the License, or (at your option) any later version.
**
-** You may not copy, print, publish, or in any
-** other way distribute this software without
-** a prior written agreement with
-** the copyright holder.
+** This package is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
extern "C"
{
-#include "libavformat/avformat.h"
+#include <avformat.h>
}
#include <synfig/general.h>
AVCodecContext *context;
//get from inside stream
- context = &stream->codec;
+ context = stream->codec;
//search for desired codec (contained in the stream)
codec = avcodec_find_encoder(context->codec_id);
int size,
ret = 0;
- AVCodecContext *context = &stream->codec;
+ AVCodecContext *context = stream->codec;
/*
If pict is invalid (NULL), then we are done compressing frames and we are trying to get
pict = encodable;
}
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index = stream->index;
+ pkt.data = (uint8_t *)pict;
+ pkt.size = sizeof(AVPicture);
+ if( context->coded_frame )
+ pkt.pts = context->coded_frame->pts;
+ if( context->coded_frame && context->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+
//cludge for raw picture format (they said they'd fix)
if (formatc->oformat->flags & AVFMT_RAWPICTURE)
{
- ret = av_write_frame(formatc, stream->index, (uint8_t *)pict, sizeof(AVPicture));
+ ret = av_write_frame(formatc, &pkt);
}
else
{
//encode our given image
size = avcodec_encode_video(context, &videobuffer[0], videobuffer.size(), pict);
- //if not zero we've got stuff to write
- if (size != 0)
+ //if greater than zero we've got stuff to write
+ if (size > 0)
{
- ret = av_write_frame(formatc, stream->index, &videobuffer[0], size);
+ av_init_packet(&pkt);
+ pkt.stream_index = stream->index;
+ pkt.data = &videobuffer[0];
+ pkt.size = size;
+ if( context->coded_frame )
+ pkt.pts = context->coded_frame->pts;
+ if( context->coded_frame && context->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+
+ ret = av_write_frame(formatc, &pkt);
//error detect - possibly throw later...
- if(ret != 0)
+ if(ret < 0)
{
synfig::warning("write_frame: error while writing video frame");
return false;
void close(AVFormatContext *formatc, AVStream *stream)
{
if(stream)
- avcodec_close(&stream->codec);
+ avcodec_close(stream->codec);
if (encodable)
{
AVFormatParameters fmtparam,*ap = &fmtparam;
memset(ap, 0, sizeof(*ap));
- ap->frame_rate = vInfo.fps;
- ap->frame_rate_base = 1;
+ // FIXME: Port next two lines to recent libavcodec versions
+ //ap->frame_rate = vInfo.fps;
+ //ap->frame_rate_base = 1;
ap->width = vInfo.w;
ap->height = vInfo.h;
//ap->pix_fmt = frame_pix_fmt;
return 0;
}
- context = &st->codec;
+ context = st->codec;
context->codec_id = (CodecID)codec_id;
context->codec_type = CODEC_TYPE_VIDEO;
context->bit_rate = info.bitrate; //TODO: Make dependant on the quality
/* frames per second */
- context->frame_rate = info.fps;
- context->frame_rate_base = 1;
+ // FIXME: Port next two lines to recent libavcodec versions
+ //context->frame_rate = info.fps;
+ //context->frame_rate_base = 1;
/* "High Quality" */
context->mb_decision=FF_MB_DECISION_BITS;
return 0;
}
- context = &stream->codec;
+ context = stream->codec;
context->codec_id = (CodecID)codec_id;
context->codec_type = CODEC_TYPE_AUDIO;