32 #include <lame/lame.h>
34 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4)
37 lame_global_flags *
gfp;
53 if ((s->
gfp = lame_init()) ==
NULL)
59 lame_set_quality(s->
gfp, 5);
66 lame_set_brate(s->
gfp, 0);
67 lame_set_VBR(s->
gfp, vbr_default);
70 lame_set_bWriteVbrTag(s->
gfp,0);
71 #if FF_API_LAME_GLOBAL_OPTS
75 if (lame_init_params(s->
gfp) < 0)
91 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
96 { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
97 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
98 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }
101 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
102 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
103 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }
114 static int mp3len(
void *
data,
int *samplesPerFrame,
int *sampleRate)
116 uint32_t header =
AV_RB32(data);
117 int layerID = 3 - ((header >> 17) & 0x03);
118 int bitRateID = ((header >> 12) & 0x0f);
119 int sampleRateID = ((header >> 10) & 0x03);
121 int isPadded = ((header >> 9) & 0x01);
122 static int const mode_tab[4] = { 2, 3, 1, 0 };
123 int mode = mode_tab[(header >> 19) & 0x03];
124 int mpeg_id = mode > 0;
125 int temp0, temp1, bitRate;
127 if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 ||
132 if (!samplesPerFrame)
133 samplesPerFrame = &temp0;
140 bitRate =
sBitRates[mpeg_id][layerID][bitRateID] * 1000;
146 return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded;
150 int buf_size,
void *
data)
160 lame_result = lame_encode_buffer_interleaved(s->
gfp, data,
165 lame_result = lame_encode_buffer(s->
gfp, data, data,
175 if (lame_result < 0) {
176 if (lame_result == -1) {
179 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
193 if (len <= s->buffer_index) {
194 memcpy(frame, s->
buffer, len);
217 #define OFFSET(x) offsetof(Mp3AudioContext, x)
218 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
232 .
name =
"libmp3lame",
static const AVClass libmp3lame_class
#define FF_COMPRESSION_DEFAULT
AV_WL32 AV_WL24 AV_WL16 AV_RB32
AVFrame * coded_frame
the picture in the bitstream
static const int sBitRates[2][3][15]
AVCodec ff_libmp3lame_encoder
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 MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame, int buf_size, void *data)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const int sBitsPerSlot[3]
static int init(AVCodecParserContext *s)
static int mp3len(void *data, int *samplesPerFrame, int *sampleRate)
uint8_t buffer[BUFFER_SIZE]
static const int sSampleRates[]
#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.
static const AVOption options[]
static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
int bit_rate
the average bitrate
struct Mp3AudioContext Mp3AudioContext
int frame_size
Samples per packet, initialized when calling 'init'.
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
static const int sSamplesPerFrame[2][3]
#define CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Describe the class of an AVClass context structure.
static av_cold int MP3lame_encode_close(AVCodecContext *avctx)
int global_quality
Global quality for codecs which cannot change it per frame.
AVSampleFormat
all in native-endian format
mpeg audio declarations for both encoder and decoder.
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
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
preferred ID for decoding MPEG audio layer 1, 2 or 3