Go to the documentation of this file.
27 #include <lame/lame.h>
42 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4+1000) // FIXME: Buffer size to small? Adding 1000 to make up for it.
47 lame_global_flags *
gfp;
63 if (!
s->buffer ||
s->buffer_size -
s->buffer_index <
BUFFER_SIZE) {
66 ff_dlog(
s->avctx,
"resizing output buffer: %d -> %d\n",
s->buffer_size,
69 s->buffer_size =
s->buffer_index = 0;
72 s->buffer_size = new_size;
100 if (!(
s->gfp = lame_init()))
118 lame_set_VBR(
s->gfp, vbr_default);
123 lame_set_VBR(
s->gfp, vbr_abr);
124 lame_set_VBR_mean_bitrate_kbps(
s->gfp, avctx->
bit_rate / 1000);
126 lame_set_brate(
s->gfp, avctx->
bit_rate / 1000);
132 lame_set_lowpassfreq(
s->gfp, avctx->
cutoff);
135 lame_set_bWriteVbrTag(
s->gfp,0);
138 lame_set_disable_reservoir(
s->gfp, !
s->reservoir);
141 if (lame_init_params(
s->gfp) < 0) {
157 sizeof(*
s->samples_flt[ch]));
158 if (!
s->samples_flt[ch]) {
182 #define ENCODE_BUFFER(func, buf_type, buf_name) do { \
183 lame_result = func(s->gfp, \
184 (const buf_type *)buf_name[0], \
185 (const buf_type *)buf_name[1], frame->nb_samples, \
186 s->buffer + s->buffer_index, \
187 s->buffer_size - s->buffer_index); \
195 int len,
ret, ch, discard_padding;
213 s->fdsp->vector_fmul_scalar(
s->samples_flt[ch],
214 (
const float *)
frame->data[ch],
223 }
else if (!
s->afq.frame_alloc) {
226 lame_result = lame_encode_flush(
s->gfp,
s->buffer +
s->buffer_index,
227 s->buffer_size -
s->buffer_index);
229 if (lame_result < 0) {
230 if (lame_result == -1) {
232 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
233 s->buffer_index,
s->buffer_size -
s->buffer_index);
237 s->buffer_index += lame_result;
253 if (
s->buffer_index < 4)
265 len = hdr.frame_size;
268 if (len <= s->buffer_index) {
271 memcpy(avpkt->
data,
s->buffer,
len);
272 s->buffer_index -=
len;
273 memmove(
s->buffer,
s->buffer +
len,
s->buffer_index);
286 if ((!
s->delay_sent && avctx->
initial_padding > 0) || discard_padding > 0) {
294 if (!
s->delay_sent) {
298 AV_WL32(side_data + 4, discard_padding);
306 #define OFFSET(x) offsetof(LAMEContext, x)
307 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
328 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
332 .
p.
name =
"libmp3lame",
355 .p.wrapper_name =
"libmp3lame",
static void error(const char *err)
int frame_size
Number of samples per channel in an audio frame.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
@ AV_SAMPLE_FMT_FLTP
float, planar
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
#define AV_CHANNEL_LAYOUT_STEREO
int sample_rate
samples per second
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
#define AV_CH_LAYOUT_MONO
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
This structure describes decoded (raw) audio or video data.
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int nb_channels
Number of channels in this layout.
#define FF_COMPRESSION_DEFAULT
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
int initial_padding
Audio only.
int flags
AV_CODEC_FLAG_*.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define FF_CODEC_ENCODE_CB(func)
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define AV_CH_LAYOUT_STEREO
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const FFCodecDefault libmp3lame_defaults[]
static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
int global_quality
Global quality for codecs which cannot change it per frame.
int(* init)(AVBSFContext *ctx)
#define CODEC_OLD_CHANNEL_LAYOUTS(...)
static int realloc_buffer(LAMEContext *s)
#define CODEC_LONG_NAME(str)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVClass libmp3lame_class
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
An AVChannelLayout holds information about the channel layout of audio data.
enum AVSampleFormat sample_fmt
audio sample format
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
#define ENCODE_BUFFER(func, buf_type, buf_name)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AVERROR_EXTERNAL
Generic error in an external library.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define av_malloc_array(a, b)
int cutoff
Audio cutoff bandwidth (0 means "automatic")
AVSampleFormat
Audio sample formats.
const char * name
Name of the codec implementation.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
main external API structure.
const FFCodec ff_libmp3lame_encoder
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static const AVOption options[]
static const int libmp3lame_sample_rates[]
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static av_cold int mp3lame_encode_close(AVCodecContext *avctx)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CHANNEL_LAYOUT_MONO
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.