FFmpeg
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"
29 #include "libavformat/avformat.h"
30 #include "libavformat/id3v2.h"
31 
32 static 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 
38 int 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 |= FF_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 }
level
uint8_t level
Definition: svq3.c:208
printf
__device__ int printf(const char *,...)
id3v2.h
avio_open
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:503
ff_id3v2_read
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:1171
ID3v2ExtraMeta
Definition: id3v2.h:84
s
#define s(width, name)
Definition: cbs_vp9.c:198
FF_FDEBUG_ID3V2
#define FF_FDEBUG_ID3V2
Definition: avformat.h:1560
AVFormatContext
Format I/O context.
Definition: avformat.h:1283
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:472
NULL
#define NULL
Definition: coverity.c:32
av_log_set_callback
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:492
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:164
ID3v2_DEFAULT_MAGIC
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition: id3v2.h:35
log_to_stdout
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
log.h
tag
uint32_t tag
Definition: movenc.c:2049
ret
ret
Definition: filter_design.txt:187
avformat.h
dict.h
main
int main(int argc, char *argv[])
Definition: id3v2.c:38
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:148
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
AVDictionaryEntry
Definition: dict.h:90
avio_closep
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:655
ff_id3v2_free_extra_meta
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition: id3v2.c:1177
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42