27 #include <lame/lame.h>
41 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4)
46 lame_global_flags *
gfp;
95 if ((s->
gfp = lame_init()) ==
NULL)
107 lame_set_quality(s->
gfp, 5);
113 lame_set_VBR(s->
gfp, vbr_default);
121 lame_set_bWriteVbrTag(s->
gfp,0);
127 if (lame_init_params(s->
gfp) < 0) {
133 avctx->
delay = lame_get_encoder_delay(s->
gfp) + 528 + 1;
141 for (ch = 0; ch < avctx->
channels; ch++) {
163 #define ENCODE_BUFFER(func, buf_type, buf_name) do { \
164 lame_result = func(s->gfp, \
165 (const buf_type *)buf_name[0], \
166 (const buf_type *)buf_name[1], frame->nb_samples, \
167 s->buffer + s->buffer_index, \
168 s->buffer_size - s->buffer_index); \
172 const AVFrame *frame,
int *got_packet_ptr)
192 for (ch = 0; ch < avctx->
channels; ch++) {
194 (
const float *)frame->
data[ch],
207 if (lame_result < 0) {
208 if (lame_result == -1) {
210 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
237 len = hdr.frame_size;
240 if (len <= s->buffer_index) {
259 #define OFFSET(x) offsetof(LAMEContext, x)
260 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
279 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
283 .
name =
"libmp3lame",
static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static const AVClass libmp3lame_class
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define FF_COMPRESSION_DEFAULT
This structure describes decoded (raw) audio or video data.
static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
static const int libmp3lame_sample_rates[]
AVCodec ff_libmp3lame_encoder
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
#define AV_CH_LAYOUT_STEREO
static av_cold int mp3lame_encode_close(AVCodecContext *avctx)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
enum AVSampleFormat sample_fmt
audio sample format
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define CODEC_FLAG_QSCALE
Use fixed qscale.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static const AVOption options[]
static const AVCodecDefault libmp3lame_defaults[]
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
static int realloc_buffer(LAMEContext *s)
int bit_rate
the average bitrate
audio channel layout utility functions
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
int frame_size
Number of samples per channel in an audio frame.
Libavcodec external API header.
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void close(AVCodecParserContext *s)
#define AVERROR_BUG
Bug detected, please report the issue.
Describe the class of an AVClass context structure.
int global_quality
Global quality for codecs which cannot change it per frame.
av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
common internal and external API header
AVSampleFormat
Audio Sample Formats.
mpeg audio declarations for both encoder and decoder.
static av_cold int init(AVCodecParserContext *s)
#define ENCODE_BUFFER(func, buf_type, buf_name)
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int *duration)
Remove frame(s) from the queue.
int channels
number of audio channels
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...