27 #include "libavutil/avstring.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/dict.h"
34 #include "libavutil/avassert.h"
62 buf[126] = atoi(tag->
value);
78 #define XING_NUM_BAGS 400
79 #define XING_TOC_SIZE 100
81 #define XING_MAX_SIZE (32 + 4 + 4 + 4 + 4 + XING_TOC_SIZE)
119 int best_bitrate_idx = -1;
120 int best_bitrate_error= INT_MAX;
124 int srate_idx, ver = 0, i, channels;
135 else if (codec->
sample_rate == base_freq / 2) ver = 0x2;
136 else if (codec->
sample_rate == base_freq / 4) ver = 0x0;
151 "not writing Xing header.\n");
156 header = 0xff
U << 24;
157 header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16;
158 header |= (srate_idx << 2) << 8;
159 header |= channels << 6;
161 for (bitrate_idx=1; bitrate_idx<15; bitrate_idx++) {
165 if(error < best_bitrate_error){
166 best_bitrate_error= error;
167 best_bitrate_idx = bitrate_idx;
172 for (bitrate_idx= best_bitrate_idx;; bitrate_idx++) {
173 if (15 == bitrate_idx)
175 mask = bitrate_idx << (4+8);
178 xing_offset=
xing_offtbl[c.lsf == 1][c.nb_channels == 1];
189 if (needed <= c.frame_size)
201 mp3->
size = c.frame_size;
213 for (i = 0; i < strlen(vendor); ++i)
242 mp3->
bag[i >> 1] = mp3->
bag[i];
247 mp3->
pos = XING_NUM_BAGS / 2;
265 "is invalid, writing it anyway.\n", pkt->
size, head);
275 #ifdef FILTER_VBR_HEADERS
277 base = 4 +
xing_offtbl[c.lsf == 1][c.nb_channels == 1];
279 if (base + 4 <= pkt->
size) {
282 if (
MKBETAG(
'X',
'i',
'n',
'g') == v ||
MKBETAG(
'I',
'n',
'f',
'o') == v)
304 int ret = 0, write = 1;
309 while ((pktl = mp3->
queue)) {
339 int seek_point = 256LL * mp3->
bag[j] / mp3->
size;
353 "attached pictures.\n");
373 return MKTAG(
'A',
'P',
'I',
'C');
383 .mime_type =
"audio/x-mpeg",
384 .extensions =
"mp2,m2a,mpa",
395 {
"id3v2_version",
"Select ID3v2 version to write. Currently 3 and 4 are supported.",
397 {
"write_id3v1",
"Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
402 static const AVClass mp3_muxer_class = {
475 "audio stream is required.\n");
506 .mime_type =
"audio/x-mpeg",
516 .priv_class = &mp3_muxer_class,
void av_free_packet(AVPacket *pkt)
Free a packet.
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)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVCodecContext * codec
Codec context associated with this stream.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
mpeg audio layer common tables.
uint64_t bag[XING_NUM_BAGS]
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static void mp3_update_xing(AVFormatContext *s)
static int mp3_write_trailer(struct AVFormatContext *s)
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const uint16_t avpriv_mpa_freq_tab[3]
static const uint8_t xing_offtbl[2][2]
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
const OptionDef options[]
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
void * priv_data
Format private data.
#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
void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb)
Finalize an opened ID3v2 tag.
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
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
A list of all streams in the file.
static int mp3_write_xing(AVFormatContext *s)
#define FF_ARRAY_ELEMS(a)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
Convert and write all global metadata from s into an ID3v2 tag.
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)
static int query_codec(enum AVCodecID id, int std_compliance)
enum AVMediaType codec_type
int sample_rate
samples per second
main external API structure.
AVIOContext * pb
I/O context.
Describe the class of an AVClass context structure.
#define MKTAG(a, b, c, d)
#define MKBETAG(a, b, c, d)
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.
static int mp3_queue_flush(AVFormatContext *s)
mpeg audio declarations for both encoder and decoder.
int64_t nb_frames
number of frames in this stream if known or 0
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
int channels
number of audio channels
static void write_header(FFV1Context *f)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
const char *const ff_id3v1_genre_str[ID3v1_GENRE_MAX+1]
ID3v1 genres.
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void mp3_xing_add_frame(MP3Context *mp3, AVPacket *pkt)
struct AVPacketList * next