27 #include <vorbis/vorbisenc.h>
39 #define OGGVORBIS_FRAME_SIZE 64
41 #define BUFFER_SIZE (1024 * 64)
85 if (vorbis_encode_setup_vbr(vi, avccontext->
channels,
94 if (vorbis_encode_setup_managed(vi, avccontext->
channels,
100 if (minrate == -1 && maxrate == -1)
101 if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET,
NULL))
106 if (avccontext->
cutoff > 0) {
107 cfreq = avccontext->
cutoff / 1000.0;
108 if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
113 vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->
iblock);
116 return vorbis_encode_setup_init(vi);
122 return 1 + l / 255 + l;
132 vorbis_info_init(&context->
vi);
137 vorbis_analysis_init(&context->
vd, &context->
vi);
138 vorbis_block_init(&context->
vd, &context->
vb);
140 vorbis_comment_init(&context->
vc);
143 vorbis_analysis_headerout(&context->
vd, &context->
vc, &header,
144 &header_comm, &header_code);
155 memcpy(&p[offset], header.packet, header.bytes);
156 offset += header.bytes;
157 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
158 offset += header_comm.bytes;
159 memcpy(&p[offset], header_code.packet, header_code.bytes);
160 offset += header_code.bytes;
164 vorbis_block_clear(&context->
vb);
165 vorbis_dsp_clear(&context->
vd);
166 vorbis_info_clear(&context->
vi);
168 vorbis_comment_clear(&context->
vc);
179 unsigned char *packets,
180 int buf_size,
void *
data)
184 signed short *audio =
data;
190 int c, channels = context->
vi.channels;
192 buffer = vorbis_analysis_buffer(&context->
vd, samples);
193 for (c = 0; c < channels; c++) {
194 int co = (channels > 8) ? c :
197 buffer[c][l] = audio[l * channels + co] / 32768.
f;
199 vorbis_analysis_wrote(&context->
vd, samples);
202 vorbis_analysis_wrote(&context->
vd, 0);
206 while (vorbis_analysis_blockout(&context->
vd, &context->
vb) == 1) {
207 vorbis_analysis(&context->
vb,
NULL);
208 vorbis_bitrate_addblock(&context->
vb);
210 while (vorbis_bitrate_flushpacket(&context->
vd, &op)) {
213 if (op.bytes == 1 && op.e_o_s)
241 memcpy(packets, op2->packet, l);
255 vorbis_analysis_wrote(&context->
vd, 0);
257 vorbis_block_clear(&context->
vb);
258 vorbis_dsp_clear(&context->
vd);
259 vorbis_info_clear(&context->
vi);
278 .priv_class = &
class,
static const AVCodecDefault defaults[]
#define OGGVORBIS_FRAME_SIZE
#define AV_OPT_FLAG_AUDIO_PARAM
AVFrame * coded_frame
the picture in the bitstream
struct OggVorbisContext OggVorbisContext
uint8_t buffer[BUFFER_SIZE]
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
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 ...
static int oggvorbis_encode_frame(AVCodecContext *avccontext, unsigned char *packets, int buf_size, void *data)
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const AVOption options[]
static int init(AVCodecParserContext *s)
AVCodec ff_libvorbis_encoder
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int rc_max_rate
maximum bitrate
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
int bit_rate
the average bitrate
static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)
int frame_size
Samples per packet, initialized when calling 'init'.
static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)
const uint8_t ff_vorbis_encoding_channel_layout_offsets[8][8]
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
#define CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
rational number numerator/denominator
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int global_quality
Global quality for codecs which cannot change it per frame.
common internal api header.
AVSampleFormat
all in native-endian format
int cutoff
Audio cutoff bandwidth (0 means "automatic")
static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, int64_t *fpos)
int channels
number of audio channels
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
static int op(uint8_t **dst, const uint8_t *dst_end, const uint8_t **buf, const uint8_t *buf_end, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int rc_min_rate
minimum bitrate
static int xiph_len(int l)