65 buf[126] = atoi(tag->
value);
81 #define XING_NUM_BAGS 400
82 #define XING_TOC_SIZE 100
137 int srate_idx, i, channels;
139 int best_bitrate_idx = -1;
140 int best_bitrate_error = INT_MAX;
152 else if (codec->
sample_rate == base_freq / 2) ver = 0x2;
153 else if (codec->
sample_rate == base_freq / 4) ver = 0x0;
168 "not writing Xing header.\n");
173 header = 0xff
U << 24;
174 header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16;
175 header |= (srate_idx << 2) << 8;
176 header |= channels << 6;
178 for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
182 if (error < best_bitrate_error) {
183 best_bitrate_error = error;
184 best_bitrate_idx = bitrate_idx;
189 for (bitrate_idx = best_bitrate_idx; ; bitrate_idx++) {
191 if (15 == bitrate_idx)
199 if (bytes_needed <= mpah.frame_size)
213 avio_wb32(dyn_ctx, 0x01 | 0x02 | 0x04 | 0x08);
215 mp3->
size = mpah.frame_size;
233 uint8_t encoder_str[9] = { 0 };
234 if ( strlen(enc->
value) >
sizeof(encoder_str)
235 && !strcmp(
"Lavc libmp3lame", enc->
value)) {
236 memcpy(encoder_str,
"Lavf lame", 9);
238 memcpy(encoder_str, enc->
value,
FFMIN(strlen(enc->
value),
sizeof(encoder_str)));
240 avio_write(dyn_ctx, encoder_str,
sizeof(encoder_str));
265 ffio_fill(dyn_ctx, 0, mpah.frame_size - bytes_needed);
294 mp3->
bag[i >> 1] = mp3->
bag[i];
299 mp3->
pos = XING_NUM_BAGS / 2;
324 "is invalid, writing it anyway.\n", pkt->
size, h);
327 #ifdef FILTER_VBR_HEADERS
329 base = 4 +
xing_offtbl[mpah.lsf == 1][mpah.nb_channels == 1];
331 if (base + 4 <= pkt->
size) {
334 if (
MKBETAG(
'X',
'i',
'n',
'g') == v ||
MKBETAG(
'I',
'n',
'f',
'o') == v)
360 int ret = 0, write = 1;
365 while ((pktl = mp3->
queue)) {
395 int seek_point = 256LL * mp3->
bag[j] / mp3->
size;
396 toc[i] =
FFMIN(seek_point, 255);
402 if (rg && rg_size >=
sizeof(*rg)) {
441 "attached pictures.\n");
463 return MKTAG(
'A',
'P',
'I',
'C');
473 .mime_type =
"audio/mpeg",
474 .extensions =
"mp2,m2a,mpa",
485 {
"id3v2_version",
"Select ID3v2 version to write. Currently 3 and 4 are supported.",
487 {
"write_id3v1",
"Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
489 {
"write_xing",
"Write the Xing header containing file duration.",
494 static const AVClass mp3_muxer_class = {
579 "audio stream is required.\n");
596 "ID3v2 header is disabled.\n");
619 .mime_type =
"audio/mpeg",
629 .priv_class = &mp3_muxer_class,