FFmpeg: libavformat/id3v2enc.c Source File
Go to the documentation of this file. 1 /*
2 * ID3v2 header writer
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22 #include <string.h>
23
32
34 {
39 }
40
42 {
43 while (*str && *str < 128) str++;
44 return !*str;
45 }
46
49 {
51
55 } else
57
58 put(pb, str);
59 }
60
61 /**
62 * Write a text frame with one (normal frames) or two (TXXX frames) strings
63 * according to encoding (only UTF-8 or UTF-16+BOM supported).
64 * @return number of bytes written or a negative error code.
65 */
68 {
70 uint8_t *pb;
74
75 /* check if the strings are ASCII-only and use UTF16 only if
76 * they're not */
80
83 if (str2)
86
88 /* ID3v2.3 frame size is not sync-safe */
91 else
95
98 }
99
100 /**
101 * Write a priv frame with owner and data. 'key' is the owner prepended with
102 * ID3v2_PRIV_METADATA_PREFIX. 'data' is provided as a string. Any \xXX
103 * (where 'X' is a valid hex digit) will be unescaped to the byte value.
104 */
106 {
108 uint8_t *pb;
110
112 return 0;
113 }
114
117
118 // owner + null byte.
120
124 char digits[] = {
data[0],
data[1], 0};
127 } else {
132 }
133 } else {
135 }
136 }
137
139
143 else
147
149
151 }
152
155 {
158
159 if (t->
key[0] !=
'T' || strlen(t->
key) != 4)
160 return -1;
165 return -1;
166 }
167
169 {
173 char year[5] = {0}, day_month[5] = {0};
175
179 /* split date tag using "YYYY-MM-DD" format into year and month/day segments */
186
196 }
197 } else
199 } else
201 }
204 }
205
207 const char *magic)
208 {
210
214
215 /* reserve space for size */
218 }
219
222 {
225
231
235 continue;
236 }
240 continue;
241 }
242
245 continue;
246 }
else if (
ret < 0) {
248 }
249
250 /* unknown tag, write as TXXX frame */
254 }
255
256 return 0;
257 }
258
260 {
261 uint8_t *dyn_buf;
265
266 if (
s->nb_chapters == 0)
267 return 0;
268
271
275 for (
int i = 0;
i <
s->nb_chapters;
i++) {
278 }
281
286
288
290 }
291
293 {
296 uint8_t *dyn_buf;
300
303
306
313
316
319
324
327
329 }
330
332 {
336
340
343
344 for (
i = 0;
i <
s->nb_chapters;
i++) {
347 }
348
349 return 0;
350 }
351
353 {
356
358 uint8_t *buf;
360 const char *mimetype =
NULL, *
desc =
"";
364
365 /* get the mimetype*/
368 mimetype = mime->
str;
369 break;
370 }
371 mime++;
372 }
373 if (!mimetype) {
375 "write an attached picture.\n", st->
index);
377 }
378
379 /* get the picture type */
384 break;
385 }
386 }
387
388 /* get the description */
391
392 /* use UTF16 only for non-ASCII strings */
395
396 /* start writing */
399
406
410 else
415
417
418 return 0;
419 }
420
422 int padding_bytes)
423 {
425
426 if (padding_bytes < 0)
427 padding_bytes = 10;
428
429 /* The ID3v2.3 specification states that 28 bits are used to represent the
430 * size of the whole tag. Therefore the current size of the tag needs to be
431 * subtracted from the upper limit of 2^28-1 to clip the value correctly. */
432 /* The minimum of 10 is an arbitrary amount of padding at the end of the tag
433 * to fix cover art display with some software such as iTunes, Traktor,
434 * Serato, Torq. */
435 padding_bytes =
av_clip(padding_bytes, 10, 268435455 - id3->
len);
437 id3->
len += padding_bytes;
438
443 }
444
446 const char *magic)
447 {
450
455
456 return 0;
457 }
static av_const int av_isxdigit(int c)
Locale-independent conversion of ASCII isxdigit.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
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 int write_metadata(AVIOContext *pb, AVDictionary **metadata, ID3v2EncContext *id3, int enc)
int len
size of the tag written so far
const char ff_id3v2_4_tags[][4]
ID3v2.4-only text information frames.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int version
ID3v2 minor version, either 3 or 4.
static const uint16_t table[]
void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb, int padding_bytes)
Finalize an opened ID3v2 tag.
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
Convert and write all global metadata from s into an ID3v2 tag.
void avio_wl16(AVIOContext *s, unsigned int val)
static void id3v2_encode_string(AVIOContext *pb, const uint8_t *str, enum ID3v2Encoding enc)
static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *str1, const char *str2, uint32_t tag, enum ID3v2Encoding enc)
Write a text frame with one (normal frames) or two (TXXX frames) strings according to encoding (only ...
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define ID3v2_PRIV_METADATA_PREFIX
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int ff_id3v2_write_simple(struct AVFormatContext *s, int id3v2_version, const char *magic)
Write an ID3v2 tag containing all global metadata from s.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int64_t end
chapter start/end time in time_base units
static void id3v2_put_size(AVIOContext *pb, int size)
static void id3v2_3_metadata_split_date(AVDictionary **pm)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int id3v2_put_priv(ID3v2EncContext *id3, AVIOContext *avioc, const char *key, const char *data)
Write a priv frame with owner and data.
void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version, const char *magic)
Initialize an ID3v2 tag.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Rational number (pair of numerator and denominator).
int64_t size_pos
offset of the tag total size
void avio_w8(AVIOContext *s, int b)
void ffio_fill(AVIOContext *s, int b, int64_t count)
const char *const ff_id3v2_picture_types[21]
#define ID3v2_HEADER_SIZE
const char ff_id3v2_3_tags[][4]
ID3v2.3-only text information frames.
const CodecMime ff_id3v2_mime_tags[]
static int id3v2_check_write_tag(ID3v2EncContext *id3, AVIOContext *pb, const AVDictionaryEntry *t, const char table[][4], enum ID3v2Encoding enc)
const char ff_id3v2_tags[][4]
A list of text information frames allowed in both ID3 v2.3 and v2.4 http://www.id3....
@ ID3v2_ENCODING_UTF16BOM
int ff_standardize_creation_time(AVFormatContext *s)
Standardize creation_time metadata in AVFormatContext to an ISO-8601 timestamp string.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#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
const AVMetadataConv ff_id3v2_34_metadata_conv[]
static int write_ctoc(AVFormatContext *s, ID3v2EncContext *id3, int enc)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
Write an attached picture from pkt into an ID3v2 tag.
#define i(width, name, range_min, range_max)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int index
stream index in AVFormatContext
const AVMetadataConv ff_id3v2_4_metadata_conv[]
static int string_is_ascii(const uint8_t *str)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
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.
AVRational time_base
time base in which the start/end timestamps are specified
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
static int write_chapter(AVFormatContext *s, ID3v2EncContext *id3, int id, int enc)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Generated on Fri Aug 22 2025 13:59:29 for FFmpeg by
doxygen
1.8.17