2007-01-25 01:16:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Paul Richards <paul.richards@gmail.com>
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2007-01-25 01:16:28 +01:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-01-25 01:16:28 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-01-25 01:16:28 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-07-05 12:40:25 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-01-25 01:16:28 +01:00
|
|
|
*/
|
|
|
|
|
2010-04-20 16:23:00 +02:00
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2010-04-20 16:23:00 +02:00
|
|
|
* @brief Theora encoder using libtheora.
|
|
|
|
* @author Paul Richards <paul.richards@gmail.com>
|
2007-01-25 01:16:28 +01:00
|
|
|
*
|
|
|
|
* A lot of this is copy / paste from other output codecs in
|
|
|
|
* libavcodec or pure guesswork (or both).
|
|
|
|
*
|
|
|
|
* I have used t_ prefixes on variables which are libtheora types
|
|
|
|
* and o_ prefixes on variables which are libogg types.
|
|
|
|
*/
|
|
|
|
|
2011-04-15 22:30:26 +02:00
|
|
|
/* Libav includes */
|
2012-08-06 15:49:32 +02:00
|
|
|
#include "libavutil/common.h"
|
2009-01-12 00:26:52 +01:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2008-05-09 13:56:36 +02:00
|
|
|
#include "libavutil/log.h"
|
2009-11-22 22:08:40 +01:00
|
|
|
#include "libavutil/base64.h"
|
2007-01-25 01:16:28 +01:00
|
|
|
#include "avcodec.h"
|
2012-02-12 09:32:40 +01:00
|
|
|
#include "internal.h"
|
2007-01-25 01:16:28 +01:00
|
|
|
|
|
|
|
/* libtheora includes */
|
2009-11-22 22:08:37 +01:00
|
|
|
#include <theora/theoraenc.h>
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-10-19 17:51:34 +02:00
|
|
|
typedef struct TheoraContext {
|
2009-11-22 22:08:37 +01:00
|
|
|
th_enc_ctx *t_state;
|
2009-11-22 22:08:40 +01:00
|
|
|
uint8_t *stats;
|
|
|
|
int stats_size;
|
|
|
|
int stats_offset;
|
2009-11-22 22:08:43 +01:00
|
|
|
int uv_hshift;
|
|
|
|
int uv_vshift;
|
2009-12-12 21:18:46 +01:00
|
|
|
int keyframe_mask;
|
2007-01-25 01:16:28 +01:00
|
|
|
} TheoraContext;
|
|
|
|
|
2010-06-30 17:38:06 +02:00
|
|
|
/** Concatenate an ogg_packet into the extradata. */
|
2009-10-19 17:51:34 +02:00
|
|
|
static int concatenate_packet(unsigned int* offset,
|
|
|
|
AVCodecContext* avc_context,
|
|
|
|
const ogg_packet* packet)
|
2007-01-25 01:16:28 +01:00
|
|
|
{
|
2009-07-13 03:59:48 +02:00
|
|
|
const char* message = NULL;
|
2009-10-19 17:51:34 +02:00
|
|
|
uint8_t* newdata = NULL;
|
2007-01-25 01:16:28 +01:00
|
|
|
int newsize = avc_context->extradata_size + 2 + packet->bytes;
|
|
|
|
|
|
|
|
if (packet->bytes < 0) {
|
|
|
|
message = "ogg_packet has negative size";
|
|
|
|
} else if (packet->bytes > 0xffff) {
|
|
|
|
message = "ogg_packet is larger than 65535 bytes";
|
|
|
|
} else if (newsize < avc_context->extradata_size) {
|
|
|
|
message = "extradata_size would overflow";
|
|
|
|
} else {
|
|
|
|
newdata = av_realloc(avc_context->extradata, newsize);
|
2009-10-20 00:26:52 +02:00
|
|
|
if (!newdata)
|
2007-01-25 01:16:28 +01:00
|
|
|
message = "av_realloc failed";
|
|
|
|
}
|
2009-10-20 00:26:52 +02:00
|
|
|
if (message) {
|
2007-01-25 01:16:28 +01:00
|
|
|
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-19 17:51:34 +02:00
|
|
|
avc_context->extradata = newdata;
|
2007-01-25 01:16:28 +01:00
|
|
|
avc_context->extradata_size = newsize;
|
2007-06-02 03:41:07 +02:00
|
|
|
AV_WB16(avc_context->extradata + (*offset), packet->bytes);
|
|
|
|
*offset += 2;
|
2009-10-19 17:51:34 +02:00
|
|
|
memcpy(avc_context->extradata + (*offset), packet->packet, packet->bytes);
|
2007-01-25 01:16:28 +01:00
|
|
|
(*offset) += packet->bytes;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
static int get_stats(AVCodecContext *avctx, int eos)
|
|
|
|
{
|
2009-11-25 17:00:14 +01:00
|
|
|
#ifdef TH_ENCCTL_2PASS_OUT
|
2009-11-22 22:08:40 +01:00
|
|
|
TheoraContext *h = avctx->priv_data;
|
|
|
|
uint8_t *buf;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_OUT, &buf, sizeof(buf));
|
|
|
|
if (bytes < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error getting first pass stats\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!eos) {
|
|
|
|
h->stats = av_fast_realloc(h->stats, &h->stats_size,
|
|
|
|
h->stats_offset + bytes);
|
|
|
|
memcpy(h->stats + h->stats_offset, buf, bytes);
|
|
|
|
h->stats_offset += bytes;
|
|
|
|
} else {
|
2010-06-04 03:15:41 +02:00
|
|
|
int b64_size = AV_BASE64_SIZE(h->stats_offset);
|
2009-11-22 22:08:40 +01:00
|
|
|
// libtheora generates a summary header at the end
|
|
|
|
memcpy(h->stats, buf, bytes);
|
|
|
|
avctx->stats_out = av_malloc(b64_size);
|
|
|
|
av_base64_encode(avctx->stats_out, b64_size, h->stats, h->stats_offset);
|
|
|
|
}
|
|
|
|
return 0;
|
2009-11-25 17:00:14 +01:00
|
|
|
#else
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
|
|
|
return -1;
|
|
|
|
#endif
|
2009-11-22 22:08:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// libtheora won't read the entire buffer we give it at once, so we have to
|
|
|
|
// repeatedly submit it...
|
|
|
|
static int submit_stats(AVCodecContext *avctx)
|
|
|
|
{
|
2009-11-25 17:00:14 +01:00
|
|
|
#ifdef TH_ENCCTL_2PASS_IN
|
2009-11-22 22:08:40 +01:00
|
|
|
TheoraContext *h = avctx->priv_data;
|
|
|
|
int bytes;
|
|
|
|
if (!h->stats) {
|
|
|
|
if (!avctx->stats_in) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No statsfile for second pass\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
h->stats_size = strlen(avctx->stats_in) * 3/4;
|
|
|
|
h->stats = av_malloc(h->stats_size);
|
|
|
|
h->stats_size = av_base64_decode(h->stats, avctx->stats_in, h->stats_size);
|
|
|
|
}
|
|
|
|
while (h->stats_size - h->stats_offset > 0) {
|
|
|
|
bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_IN,
|
|
|
|
h->stats + h->stats_offset,
|
|
|
|
h->stats_size - h->stats_offset);
|
|
|
|
if (bytes < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error submitting stats\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!bytes)
|
|
|
|
return 0;
|
|
|
|
h->stats_offset += bytes;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-11-25 17:00:14 +01:00
|
|
|
#else
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n");
|
|
|
|
return -1;
|
|
|
|
#endif
|
2009-11-22 22:08:40 +01:00
|
|
|
}
|
|
|
|
|
2009-02-22 14:48:55 +01:00
|
|
|
static av_cold int encode_init(AVCodecContext* avc_context)
|
2007-01-25 01:16:28 +01:00
|
|
|
{
|
2009-11-22 22:08:37 +01:00
|
|
|
th_info t_info;
|
|
|
|
th_comment t_comment;
|
2007-01-25 01:16:28 +01:00
|
|
|
ogg_packet o_packet;
|
|
|
|
unsigned int offset;
|
|
|
|
TheoraContext *h = avc_context->priv_data;
|
2009-11-22 22:08:37 +01:00
|
|
|
uint32_t gop_size = avc_context->gop_size;
|
2007-01-25 01:16:28 +01:00
|
|
|
|
|
|
|
/* Set up the theora_info struct */
|
2009-11-22 22:08:37 +01:00
|
|
|
th_info_init(&t_info);
|
|
|
|
t_info.frame_width = FFALIGN(avc_context->width, 16);
|
|
|
|
t_info.frame_height = FFALIGN(avc_context->height, 16);
|
|
|
|
t_info.pic_width = avc_context->width;
|
|
|
|
t_info.pic_height = avc_context->height;
|
|
|
|
t_info.pic_x = 0;
|
|
|
|
t_info.pic_y = 0;
|
2007-02-07 15:10:50 +01:00
|
|
|
/* Swap numerator and denominator as time_base in AVCodecContext gives the
|
|
|
|
* time period between frames, but theora_info needs the framerate. */
|
2009-10-19 17:51:34 +02:00
|
|
|
t_info.fps_numerator = avc_context->time_base.den;
|
2007-01-25 01:16:28 +01:00
|
|
|
t_info.fps_denominator = avc_context->time_base.num;
|
2009-10-20 00:26:52 +02:00
|
|
|
if (avc_context->sample_aspect_ratio.num) {
|
2009-10-19 17:51:34 +02:00
|
|
|
t_info.aspect_numerator = avc_context->sample_aspect_ratio.num;
|
2007-01-25 01:16:28 +01:00
|
|
|
t_info.aspect_denominator = avc_context->sample_aspect_ratio.den;
|
|
|
|
} else {
|
2009-10-19 17:51:34 +02:00
|
|
|
t_info.aspect_numerator = 1;
|
2007-01-25 01:16:28 +01:00
|
|
|
t_info.aspect_denominator = 1;
|
|
|
|
}
|
2009-11-22 22:08:46 +01:00
|
|
|
|
|
|
|
if (avc_context->color_primaries == AVCOL_PRI_BT470M)
|
|
|
|
t_info.colorspace = TH_CS_ITU_REC_470M;
|
|
|
|
else if (avc_context->color_primaries == AVCOL_PRI_BT470BG)
|
|
|
|
t_info.colorspace = TH_CS_ITU_REC_470BG;
|
|
|
|
else
|
|
|
|
t_info.colorspace = TH_CS_UNSPECIFIED;
|
2009-11-22 22:08:43 +01:00
|
|
|
|
2012-10-06 12:10:34 +02:00
|
|
|
if (avc_context->pix_fmt == AV_PIX_FMT_YUV420P)
|
2009-11-22 22:08:43 +01:00
|
|
|
t_info.pixel_fmt = TH_PF_420;
|
2012-10-06 12:10:34 +02:00
|
|
|
else if (avc_context->pix_fmt == AV_PIX_FMT_YUV422P)
|
2009-11-22 22:08:43 +01:00
|
|
|
t_info.pixel_fmt = TH_PF_422;
|
2012-10-06 12:10:34 +02:00
|
|
|
else if (avc_context->pix_fmt == AV_PIX_FMT_YUV444P)
|
2009-11-22 22:08:43 +01:00
|
|
|
t_info.pixel_fmt = TH_PF_444;
|
|
|
|
else {
|
|
|
|
av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
avcodec_get_chroma_sub_sample(avc_context->pix_fmt, &h->uv_hshift, &h->uv_vshift);
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-10-01 00:25:49 +02:00
|
|
|
if (avc_context->flags & CODEC_FLAG_QSCALE) {
|
|
|
|
/* to be constant with the libvorbis implementation, clip global_quality to 0 - 10
|
|
|
|
Theora accepts a quality parameter p, which is:
|
|
|
|
* 0 <= p <=63
|
|
|
|
* an int value
|
|
|
|
*/
|
2009-10-19 17:51:34 +02:00
|
|
|
t_info.quality = av_clip(avc_context->global_quality / (float)FF_QP2LAMBDA, 0, 10) * 6.3;
|
2009-10-01 00:25:49 +02:00
|
|
|
t_info.target_bitrate = 0;
|
|
|
|
} else {
|
|
|
|
t_info.target_bitrate = avc_context->bit_rate;
|
2009-10-19 17:51:34 +02:00
|
|
|
t_info.quality = 0;
|
2009-10-01 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 01:16:28 +01:00
|
|
|
/* Now initialise libtheora */
|
2009-11-22 22:08:37 +01:00
|
|
|
h->t_state = th_encode_alloc(&t_info);
|
|
|
|
if (!h->t_state) {
|
2007-01-25 01:16:28 +01:00
|
|
|
av_log(avc_context, AV_LOG_ERROR, "theora_encode_init failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-12 21:18:46 +01:00
|
|
|
h->keyframe_mask = (1 << t_info.keyframe_granule_shift) - 1;
|
2007-01-25 01:16:28 +01:00
|
|
|
/* Clear up theora_info struct */
|
2009-11-22 22:08:37 +01:00
|
|
|
th_info_clear(&t_info);
|
|
|
|
|
|
|
|
if (th_encode_ctl(h->t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
|
|
|
&gop_size, sizeof(gop_size))) {
|
|
|
|
av_log(avc_context, AV_LOG_ERROR, "Error setting GOP size\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
// need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers
|
|
|
|
if (avc_context->flags & CODEC_FLAG_PASS1) {
|
|
|
|
if (get_stats(avc_context, 0))
|
|
|
|
return -1;
|
|
|
|
} else if (avc_context->flags & CODEC_FLAG_PASS2) {
|
|
|
|
if (submit_stats(avc_context))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-01-25 01:16:28 +01:00
|
|
|
/*
|
|
|
|
Output first header packet consisting of theora
|
|
|
|
header, comment, and tables.
|
|
|
|
|
|
|
|
Each one is prefixed with a 16bit size, then they
|
2011-10-30 18:02:42 +01:00
|
|
|
are concatenated together into libavcodec's extradata.
|
2007-01-25 01:16:28 +01:00
|
|
|
*/
|
|
|
|
offset = 0;
|
|
|
|
|
2009-11-22 22:08:37 +01:00
|
|
|
/* Headers */
|
|
|
|
th_comment_init(&t_comment);
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-11-22 22:08:37 +01:00
|
|
|
while (th_encode_flushheader(h->t_state, &t_comment, &o_packet))
|
|
|
|
if (concatenate_packet(&offset, avc_context, &o_packet))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
th_comment_clear(&t_comment);
|
2007-01-25 01:16:28 +01:00
|
|
|
|
|
|
|
/* Set up the output AVFrame */
|
|
|
|
avc_context->coded_frame= avcodec_alloc_frame();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-12 09:32:40 +01:00
|
|
|
static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
|
|
|
|
const AVFrame *frame, int *got_packet)
|
2007-01-25 01:16:28 +01:00
|
|
|
{
|
2009-11-22 22:08:37 +01:00
|
|
|
th_ycbcr_buffer t_yuv_buffer;
|
2007-01-25 01:16:28 +01:00
|
|
|
TheoraContext *h = avc_context->priv_data;
|
|
|
|
ogg_packet o_packet;
|
2012-02-12 09:32:40 +01:00
|
|
|
int result, i, ret;
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
// EOS, finish and get 1st pass stats if applicable
|
|
|
|
if (!frame) {
|
|
|
|
th_encode_packetout(h->t_state, 1, &o_packet);
|
|
|
|
if (avc_context->flags & CODEC_FLAG_PASS1)
|
|
|
|
if (get_stats(avc_context, 1))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-25 01:16:28 +01:00
|
|
|
/* Copy planes to the theora yuv_buffer */
|
2009-11-22 22:08:37 +01:00
|
|
|
for (i = 0; i < 3; i++) {
|
2009-11-22 22:08:43 +01:00
|
|
|
t_yuv_buffer[i].width = FFALIGN(avc_context->width, 16) >> (i && h->uv_hshift);
|
|
|
|
t_yuv_buffer[i].height = FFALIGN(avc_context->height, 16) >> (i && h->uv_vshift);
|
2009-11-22 22:08:37 +01:00
|
|
|
t_yuv_buffer[i].stride = frame->linesize[i];
|
|
|
|
t_yuv_buffer[i].data = frame->data[i];
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
if (avc_context->flags & CODEC_FLAG_PASS2)
|
|
|
|
if (submit_stats(avc_context))
|
|
|
|
return -1;
|
|
|
|
|
2007-01-25 01:16:28 +01:00
|
|
|
/* Now call into theora_encode_YUVin */
|
2009-11-22 22:08:37 +01:00
|
|
|
result = th_encode_ycbcr_in(h->t_state, t_yuv_buffer);
|
2009-10-20 00:26:52 +02:00
|
|
|
if (result) {
|
2007-01-25 01:16:28 +01:00
|
|
|
const char* message;
|
|
|
|
switch (result) {
|
2009-10-19 17:51:34 +02:00
|
|
|
case -1:
|
|
|
|
message = "differing frame sizes";
|
|
|
|
break;
|
2009-11-22 22:08:37 +01:00
|
|
|
case TH_EINVAL:
|
2009-10-19 17:51:34 +02:00
|
|
|
message = "encoder is not ready or is finished";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
message = "unknown reason";
|
|
|
|
break;
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
|
|
|
av_log(avc_context, AV_LOG_ERROR, "theora_encode_YUVin failed (%s) [%d]\n", message, result);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
if (avc_context->flags & CODEC_FLAG_PASS1)
|
|
|
|
if (get_stats(avc_context, 0))
|
|
|
|
return -1;
|
|
|
|
|
2007-01-25 01:16:28 +01:00
|
|
|
/* Pick up returned ogg_packet */
|
2009-11-22 22:08:37 +01:00
|
|
|
result = th_encode_packetout(h->t_state, 0, &o_packet);
|
2007-01-25 01:16:28 +01:00
|
|
|
switch (result) {
|
2009-10-19 17:51:34 +02:00
|
|
|
case 0:
|
|
|
|
/* No packet is ready */
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
/* Success, we have a packet */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed [%d]\n", result);
|
|
|
|
return -1;
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy ogg_packet content out to buffer */
|
2012-02-12 09:32:40 +01:00
|
|
|
if ((ret = ff_alloc_packet(pkt, o_packet.bytes)) < 0) {
|
|
|
|
av_log(avc_context, AV_LOG_ERROR, "Error getting output packet of size %ld.\n", o_packet.bytes);
|
|
|
|
return ret;
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
2012-02-12 09:32:40 +01:00
|
|
|
memcpy(pkt->data, o_packet.packet, o_packet.bytes);
|
2007-01-25 01:16:28 +01:00
|
|
|
|
2009-12-12 21:18:49 +01:00
|
|
|
// HACK: assumes no encoder delay, this is true until libtheora becomes
|
|
|
|
// multithreaded (which will be disabled unless explictly requested)
|
2012-02-12 09:32:40 +01:00
|
|
|
pkt->pts = pkt->dts = frame->pts;
|
2009-12-12 21:18:46 +01:00
|
|
|
avc_context->coded_frame->key_frame = !(o_packet.granulepos & h->keyframe_mask);
|
2012-02-12 09:32:40 +01:00
|
|
|
if (avc_context->coded_frame->key_frame)
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
|
|
|
*got_packet = 1;
|
2009-10-10 16:43:31 +02:00
|
|
|
|
2012-02-12 09:32:40 +01:00
|
|
|
return 0;
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
|
|
|
|
2009-02-22 14:48:55 +01:00
|
|
|
static av_cold int encode_close(AVCodecContext* avc_context)
|
2007-01-25 01:16:28 +01:00
|
|
|
{
|
|
|
|
TheoraContext *h = avc_context->priv_data;
|
|
|
|
|
2009-11-22 22:08:37 +01:00
|
|
|
th_encode_free(h->t_state);
|
2009-11-22 22:08:40 +01:00
|
|
|
av_freep(&h->stats);
|
2009-07-13 03:59:45 +02:00
|
|
|
av_freep(&avc_context->coded_frame);
|
2009-11-22 22:08:40 +01:00
|
|
|
av_freep(&avc_context->stats_out);
|
2009-07-13 03:59:45 +02:00
|
|
|
av_freep(&avc_context->extradata);
|
|
|
|
avc_context->extradata_size = 0;
|
|
|
|
|
2009-11-22 22:08:40 +01:00
|
|
|
return 0;
|
2007-01-25 01:16:28 +01:00
|
|
|
}
|
|
|
|
|
2010-04-20 16:23:00 +02:00
|
|
|
/** AVCodec struct exposed to libavcodec */
|
2011-01-25 22:40:11 +01:00
|
|
|
AVCodec ff_libtheora_encoder = {
|
2012-04-06 18:19:39 +02:00
|
|
|
.name = "libtheora",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_THEORA,
|
2007-01-25 01:16:28 +01:00
|
|
|
.priv_data_size = sizeof(TheoraContext),
|
2012-04-06 18:19:39 +02:00
|
|
|
.init = encode_init,
|
|
|
|
.close = encode_close,
|
|
|
|
.encode2 = encode_frame,
|
|
|
|
.capabilities = CODEC_CAP_DELAY, // needed to get the statsfile summary
|
2012-10-06 12:10:34 +02:00
|
|
|
.pix_fmts = (const enum AVPixelFormat[]){
|
|
|
|
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE
|
2012-04-06 18:19:39 +02:00
|
|
|
},
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("libtheora Theora"),
|
2007-01-25 01:16:28 +01:00
|
|
|
};
|