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"
61 buf[126] = atoi(tag->
value);
77 #define XING_NUM_BAGS 400
78 #define XING_TOC_SIZE 100
80 #define XING_MAX_SIZE (32 + 4 + 4 + 4 + 4 + XING_TOC_SIZE)
120 int srate_idx, i, channels;
122 int best_bitrate_idx;
123 int best_bitrate_error = INT_MAX;
126 int lsf, bytes_needed;
135 else if (codec->
sample_rate == base_freq / 2) ver = 0x2;
136 else if (codec->
sample_rate == base_freq / 4) ver = 0x0;
152 "not writing Xing header.\n");
158 header |= (0x7 << 5 | ver << 3 | 0x1 << 1 | 0x1) << 16;
159 header |= (srate_idx << 2) << 8;
160 header |= channels << 6;
162 lsf = !((header & (1 << 20) && header & (1 << 19)));
164 xing_offset =
xing_offtbl[ver != 3][channels == 1];
173 for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) {
177 if (error < best_bitrate_error){
178 best_bitrate_error = error;
179 best_bitrate_idx = bitrate_idx;
183 for (bitrate_idx = best_bitrate_idx; bitrate_idx < 15; bitrate_idx++) {
189 if (bytes_needed <= mpah.frame_size)
206 mp3->
size = mpah.frame_size;
216 ffio_fill(s->
pb, 0, mpah.frame_size - bytes_needed);
237 mp3->
bag[i / 2] = mp3->
bag[i];
242 mp3->
pos = XING_NUM_BAGS / 2;
276 int ret = 0, write = 1;
281 while ((pktl = mp3->
queue)) {
311 int seek_point = 256LL * mp3->
bag[j] / mp3->
size;
325 "attached pictures.\n");
344 .mime_type =
"audio/x-mpeg",
345 .extensions =
"mp2,m2a,mpa",
356 {
"id3v2_version",
"Select ID3v2 version to write. Currently 3 and 4 are supported.",
358 {
"write_id3v1",
"Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.",
360 {
"write_xing",
"Write the Xing header containing file duration.",
365 static const AVClass mp3_muxer_class = {
446 "audio stream is required.\n");
463 "ID3v2 header is disabled.\n");
486 .mime_type =
"audio/x-mpeg",
495 .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.
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 * 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]
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
const OptionDef options[]
#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.
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.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
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)
AVStream ** streams
A list of all streams in the file.
#define FF_ARRAY_ELEMS(a)
static void mp3_write_xing(AVFormatContext *s)
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.
AVDictionary * metadata
Metadata that applies to the whole file.
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)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
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.
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
av_default_item_name
Return the context name.
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.
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