43 #include <theora/theoraenc.h>
60 const char* message =
NULL;
64 if (packet->bytes < 0) {
65 message =
"ogg_packet has negative size";
66 }
else if (packet->bytes > 0xffff) {
67 message =
"ogg_packet is larger than 65535 bytes";
68 }
else if (newsize < avc_context->extradata_size) {
69 message =
"extradata_size would overflow";
73 message =
"av_realloc failed";
84 memcpy(avc_context->
extradata + (*offset), packet->packet, packet->bytes);
85 (*offset) += packet->bytes;
91 #ifdef TH_ENCCTL_2PASS_OUT
96 bytes = th_encode_ctl(h->
t_state, TH_ENCCTL_2PASS_OUT, &buf,
sizeof(buf));
109 memcpy(h->
stats, buf, bytes);
124 #ifdef TH_ENCCTL_2PASS_IN
137 bytes = th_encode_ctl(h->
t_state, TH_ENCCTL_2PASS_IN,
158 th_comment t_comment;
162 uint32_t gop_size = avc_context->
gop_size;
165 th_info_init(&t_info);
168 t_info.pic_width = avc_context->
width;
169 t_info.pic_height = avc_context->
height;
180 t_info.aspect_numerator = 1;
181 t_info.aspect_denominator = 1;
185 t_info.colorspace = TH_CS_ITU_REC_470M;
187 t_info.colorspace = TH_CS_ITU_REC_470BG;
189 t_info.colorspace = TH_CS_UNSPECIFIED;
192 t_info.pixel_fmt = TH_PF_420;
194 t_info.pixel_fmt = TH_PF_422;
196 t_info.pixel_fmt = TH_PF_444;
211 t_info.target_bitrate = 0;
213 t_info.target_bitrate = avc_context->
bit_rate;
218 h->
t_state = th_encode_alloc(&t_info);
226 th_info_clear(&t_info);
228 if (th_encode_ctl(h->
t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
229 &gop_size,
sizeof(gop_size))) {
253 th_comment_init(&t_comment);
255 while (th_encode_flushheader(h->
t_state, &t_comment, &o_packet))
259 th_comment_clear(&t_comment);
268 const AVFrame *frame,
int *got_packet)
270 th_ycbcr_buffer t_yuv_buffer;
277 th_encode_packetout(h->
t_state, 1, &o_packet);
285 for (i = 0; i < 3; i++) {
288 t_yuv_buffer[i].stride = frame->
linesize[i];
289 t_yuv_buffer[i].data = frame->
data[i];
297 result = th_encode_ycbcr_in(h->
t_state, t_yuv_buffer);
302 message =
"differing frame sizes";
305 message =
"encoder is not ready or is finished";
308 message =
"unknown reason";
311 av_log(avc_context,
AV_LOG_ERROR,
"theora_encode_YUVin failed (%s) [%d]\n", message, result);
320 result = th_encode_packetout(h->
t_state, 0, &o_packet);
335 av_log(avc_context,
AV_LOG_ERROR,
"Error getting output packet of size %ld.\n", o_packet.bytes);
338 memcpy(pkt->
data, o_packet.packet, o_packet.bytes);
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
AVFrame * coded_frame
the picture in the bitstream
static int concatenate_packet(unsigned int *offset, AVCodecContext *avc_context, const ogg_packet *packet)
Concatenate an ogg_packet into the extradata.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
static int submit_stats(AVCodecContext *avctx)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
#define CODEC_FLAG_QSCALE
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
char * stats_out
pass1 encoding statistics output buffer
static int init(AVCodecParserContext *s)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
static int get_stats(AVCodecContext *avctx, int eos)
int bit_rate
the average bitrate
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes.
struct TheoraContext TheoraContext
int width
picture width / height.
static av_cold int encode_init(AVCodecContext *avc_context)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
static av_cold int encode_close(AVCodecContext *avc_context)
static int encode_frame(AVCodecContext *avc_context, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, int64_t *fpos)
AVCodec ff_libtheora_encoder
AVCodec struct exposed to libavcodec.
int key_frame
1 -> keyframe, 0-> not
int av_base64_decode(uint8_t *out, const char *in, int out_size)
Decode a base64-encoded string.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...