Go to the documentation of this file.
43 uint8_t *buf,
int buf_size)
79 buf[126] = atoi(
tag->value);
95 #define XING_NUM_BAGS 400
96 #define XING_TOC_SIZE 100
155 int best_bitrate_idx = -1;
156 int best_bitrate_error = INT_MAX;
168 else if (par->
sample_rate == base_freq / 2) ver = 0x2;
169 else if (par->
sample_rate == base_freq / 4) ver = 0x0;
184 "not writing Xing header.\n");
190 header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16;
191 header |= (srate_idx << 2) << 8;
194 for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
198 if (
error < best_bitrate_error) {
199 best_bitrate_error =
error;
200 best_bitrate_idx = bitrate_idx;
205 for (bitrate_idx = best_bitrate_idx; ; bitrate_idx++) {
207 if (15 == bitrate_idx)
216 if (bytes_needed <= mpah.frame_size)
230 avio_wb32(dyn_ctx, 0x01 | 0x02 | 0x04 | 0x08);
232 mp3->
size = mpah.frame_size;
250 uint8_t encoder_str[9] = { 0 };
251 if ( strlen(enc->
value) >
sizeof(encoder_str)
252 && !strcmp(
"Lavc libmp3lame", enc->
value)) {
253 memcpy(encoder_str,
"Lavf lame", 9);
255 memcpy(encoder_str, enc->
value,
FFMIN(strlen(enc->
value),
sizeof(encoder_str)));
257 avio_write(dyn_ctx, encoder_str,
sizeof(encoder_str));
277 ffio_fill(dyn_ctx, 0, mpah.frame_size - bytes_needed);
337 "is invalid, writing it anyway.\n",
pkt->
size,
h);
340 #ifdef FILTER_VBR_HEADERS
347 if (
MKBETAG(
'X',
'i',
'n',
'g') == v ||
MKBETAG(
'I',
'n',
'f',
'o') == v)
359 uint8_t *side_data =
NULL;
360 size_t side_data_size;
370 if (side_data && side_data_size >= 10) {
387 int ret = 0, write = 1;
422 int seek_point = 256LL * mp3->
bag[j] / mp3->
size;
423 toc[
i] =
FFMIN(seek_point, 255);
428 s->streams[0]->codecpar->nb_coded_side_data,
430 if (sd && sd->
size >=
sizeof(*rg)) {
453 if (mp3->
delay >= 1 << 12) {
454 mp3->
delay = (1 << 12) - 1;
481 "attached pictures.\n");
505 return MKTAG(
'A',
'P',
'I',
'C');
512 {
"id3v2_version",
"Select ID3v2 version to write. Currently 3 and 4 are supported.",
514 {
"write_id3v1",
"Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
516 {
"write_xing",
"Write the Xing header containing file duration.",
589 for (
i = 0;
i <
s->nb_streams;
i++) {
594 "audio stream is required.\n");
611 "ID3v2 header is disabled.\n");
650 .p.mime_type =
"audio/mpeg",
651 .p.extensions =
"mp3",
static void error(const char *err)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
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
static const uint8_t xing_offtbl[2][2]
enum AVMediaType codec_type
General type of the encoded data.
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
uint64_t bag[XING_NUM_BAGS]
This struct describes the properties of an encoded stream.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
int32_t album_gain
Same as track_gain, but for the whole album.
const FFOutputFormat ff_mp3_muxer
int nb_channels
Number of channels in this layout.
void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, const char *magic)
Initialize an ID3v2 tag.
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avpriv_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
static double val(void *priv, double ch)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int mp3_write_header(struct AVFormatContext *s)
static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int query_codec(enum AVCodecID id, int std_compliance)
static int mp3_write_trailer(struct AVFormatContext *s)
int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
Convert and write all global metadata from s into an ID3v2 tag.
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static int mp3_queue_flush(AVFormatContext *s)
int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
const char * av_default_item_name(void *ptr)
Return the context name.
void avio_w8(AVIOContext *s, int b)
void ffio_fill(AVIOContext *s, int b, int64_t count)
AVChannelLayout ch_layout
Audio only.
static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
int sample_rate
Audio only.
static void mp3_xing_add_frame(MP3Context *mp3, AVPacket *pkt)
const CodecMime ff_id3v2_mime_tags[]
AVCodecID
Identify the syntax and semantics of the bitstream.
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
Write an attached picture from pkt into an ID3v2 tag.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
#define MKBETAG(a, b, c, d)
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
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
static const uint8_t header[24]
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
#define i(width, name, range_min, range_max)
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
static void mp3_deinit(struct AVFormatContext *s)
const char *const ff_id3v1_genre_str[ID3v1_GENRE_MAX+1]
ID3v1 genres.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
@ AV_OPT_TYPE_INT
Underlying C type is int.
static const AVOption options[]
const uint16_t ff_mpa_freq_tab[3]
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb, int padding_bytes)
Finalize an opened ID3v2 tag.
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1....
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
void avio_wb24(AVIOContext *s, unsigned int val)
const FF_VISIBILITY_PUSH_HIDDEN uint16_t ff_mpa_bitrate_tab[2][3][15]
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static int id3v1_set_string(AVFormatContext *s, const char *key, uint8_t *buf, int buf_size)
void avio_wb16(AVIOContext *s, unsigned int val)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
static int mp3_write_xing(AVFormatContext *s)
#define MKTAG(a, b, c, d)
static int mp3_init(struct AVFormatContext *s)
Write an ID3v2 header at beginning of stream.
static void mp3_update_xing(AVFormatContext *s)
static const AVClass mp3_muxer_class
int64_t xing_frame_offset