65 buf[126] = atoi(tag->
value);
81 #define XING_NUM_BAGS 400
82 #define XING_TOC_SIZE 100
139 int srate_idx, i, channels;
141 int best_bitrate_idx = -1;
142 int best_bitrate_error = INT_MAX;
154 else if (par->
sample_rate == base_freq / 2) ver = 0x2;
155 else if (par->
sample_rate == base_freq / 4) ver = 0x0;
170 "not writing Xing header.\n");
175 header = 0xff
U << 24;
176 header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16;
177 header |= (srate_idx << 2) << 8;
178 header |= channels << 6;
180 for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
184 if (error < best_bitrate_error) {
185 best_bitrate_error = error;
186 best_bitrate_idx = bitrate_idx;
191 for (bitrate_idx = best_bitrate_idx; ; bitrate_idx++) {
193 if (15 == bitrate_idx)
202 if (bytes_needed <= mpah.frame_size)
216 avio_wb32(dyn_ctx, 0x01 | 0x02 | 0x04 | 0x08);
218 mp3->
size = mpah.frame_size;
236 uint8_t encoder_str[9] = { 0 };
237 if ( strlen(enc->
value) >
sizeof(encoder_str)
238 && !strcmp(
"Lavc libmp3lame", enc->
value)) {
239 memcpy(encoder_str,
"Lavf lame", 9);
241 memcpy(encoder_str, enc->
value,
FFMIN(strlen(enc->
value),
sizeof(encoder_str)));
243 avio_write(dyn_ctx, encoder_str,
sizeof(encoder_str));
263 ffio_fill(dyn_ctx, 0, mpah.frame_size - bytes_needed);
292 mp3->
bag[i >> 1] = mp3->
bag[i];
297 mp3->
pos = XING_NUM_BAGS / 2;
323 "is invalid, writing it anyway.\n", pkt->
size, h);
326 #ifdef FILTER_VBR_HEADERS
328 base = 4 +
xing_offtbl[mpah.lsf == 1][mpah.nb_channels == 1];
330 if (base + 4 <= pkt->
size) {
333 if (
MKBETAG(
'X',
'i',
'n',
'g') == v ||
MKBETAG(
'I',
'n',
'f',
'o') == v)
346 int side_data_size = 0;
356 if (side_data && side_data_size >= 10) {
373 int ret = 0, write = 1;
378 while ((pktl = mp3->
queue)) {
408 int seek_point = 256LL * mp3->
bag[j] / mp3->
size;
409 toc[i] =
FFMIN(seek_point, 255);
415 if (rg && rg_size >=
sizeof(*rg)) {
437 if (mp3->
delay >= 1 << 12) {
438 mp3->
delay = (1 << 12) - 1;
465 "attached pictures.\n");
487 return MKTAG(
'A',
'P',
'I',
'C');
497 .mime_type =
"audio/mpeg",
498 .extensions =
"mp2,m2a,mpa",
509 {
"id3v2_version",
"Select ID3v2 version to write. Currently 3 and 4 are supported.",
511 {
"write_id3v1",
"Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
513 {
"write_xing",
"Write the Xing header containing file duration.",
518 static const AVClass mp3_muxer_class = {
603 "audio stream is required.\n");
620 "ID3v2 header is disabled.\n");
643 .mime_type =
"audio/mpeg",
653 .priv_class = &mp3_muxer_class,
const char const char void * val
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, const char *magic)
Initialize an ID3v2 tag.
static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
int64_t xing_frame_offset
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb, int padding_bytes)
Finalize an opened ID3v2 tag.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
mpeg audio layer common tables.
This struct describes the properties of an encoded stream.
uint64_t bag[XING_NUM_BAGS]
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void mp3_update_xing(AVFormatContext *s)
static int mp3_write_trailer(struct AVFormatContext *s)
const uint16_t avpriv_mpa_freq_tab[3]
uint8_t * av_stream_get_side_data(const AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
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
AVStream ** streams
A list of all streams in the file.
Public header for CRC hash function implementation.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static const uint8_t xing_offtbl[2][2]
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
const OptionDef options[]
int32_t album_gain
Same as track_gain, but for the whole album.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
static const uint16_t mask[17]
#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
enum AVMediaType codec_type
General type of the encoded data.
simple assert() macros that are a bit more flexible than ISO C assert().
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.
const CodecMime ff_id3v2_mime_tags[]
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int mp3_write_xing(AVFormatContext *s)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
Convert and write all global metadata from s into an ID3v2 tag.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void ffio_fill(AVIOContext *s, int b, int count)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static int write_trailer(AVFormatContext *s1)
void avio_wb24(AVIOContext *s, unsigned int val)
static int query_codec(enum AVCodecID id, int std_compliance)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FF_ARRAY_ELEMS(a)
int metadata_header_padding
Number of bytes to be written as padding in a metadata header.
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_copy_packet(AVPacket *dst, const AVPacket *src)
Copy packet, including contents.
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Describe the class of an AVClass context structure.
Recommmends skipping the specified number of samples.
void avio_wb16(AVIOContext *s, unsigned int val)
This side data should be associated with an audio stream and contains ReplayGain information in form ...
static int id3v1_set_string(AVFormatContext *s, const char *key, uint8_t *buf, int buf_size)
int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
Write an attached picture from pkt into an ID3v2 tag.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
int sample_rate
Audio only.
static int mp3_queue_flush(AVFormatContext *s)
struct AVPacketList * next
mpeg audio declarations for both encoder and decoder.
int64_t nb_frames
number of frames in this stream if known or 0
#define MKBETAG(a, b, c, d)
void * priv_data
Format private data.
static void write_header(FFV1Context *f)
void avio_wb32(AVIOContext *s, unsigned int val)
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
AVCodecParameters * codecpar
static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
#define MKTAG(a, b, c, d)
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification).
const char *const ff_id3v1_genre_str[ID3v1_GENRE_MAX+1]
ID3v1 genres.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
static void mp3_xing_add_frame(MP3Context *mp3, AVPacket *pkt)