FFmpeg
Loading...
Searching...
No Matches
id3v2.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * Reads ID3v2 tags from an MP3 file and prints the raw tag names
21 * without applying FFmpeg's internal metadata key conversion.
22 */
23
24#include <stdarg.h>
25#include <stdio.h>
26
27#include "libavutil/dict.h"
28#include "libavutil/log.h"
30#include "libavformat/id3v2.h"
31
32static void log_to_stdout(void *avcl, int level, const char *fmt, va_list vl)
33{
34 if (level <= av_log_get_level())
35 vprintf(fmt, vl);
36}
37
38int main(int argc, char *argv[])
39{
41 ID3v2ExtraMeta *extra_meta = NULL;
42 const AVDictionaryEntry *tag = NULL;
43 int ret;
44
46
47 if (argc < 2) {
48 fprintf(stderr, "Usage: %s <file>\n", argv[0]);
49 return 1;
50 }
51
53 if (!s)
54 return 1;
55
56 s->debug |= AV_FDEBUG_ID3V2;
57
58 ret = avio_open(&s->pb, argv[1], AVIO_FLAG_READ);
59 if (ret < 0) {
60 fprintf(stderr, "Failed to open '%s'\n", argv[1]);
62 return 1;
63 }
64
65 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &extra_meta, 0);
66
67 while ((tag = av_dict_iterate(s->metadata, tag)))
68 printf("%s=%s\n", tag->key, tag->value);
69
70 ff_id3v2_free_extra_meta(&extra_meta);
71 avio_closep(&s->pb);
73
74 return 0;
75}
Main libavformat public API header.
#define AV_FDEBUG_ID3V2
Definition avformat.h:1625
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition avio.c:565
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition avio.c:717
#define AVIO_FLAG_READ
read-only
Definition avio.h:617
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
Public dictionary API.
int main
Definition dovi_rpuenc.c:38
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:150
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition log.c:491
int av_log_get_level(void)
Get the current log level.
Definition log.c:471
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata.
Definition id3v2.c:1180
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition id3v2.c:1186
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition id3v2.h:35
uint32_t tag
Definition movenc.c:2087
Format I/O context.
Definition avformat.h:1333
uint8_t level
Definition svq3.c:208
static void log_to_stdout(void *avcl, int level, const char *fmt, va_list vl)
Reads ID3v2 tags from an MP3 file and prints the raw tag names without applying FFmpeg's internal met...
Definition id3v2.c:32