FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/tests/id3v2.c
Date: 2026-09-19 14:27:34
Exec Total Coverage
Lines: 21 27 77.8%
Functions: 2 2 100.0%
Branches: 7 10 70.0%

Line Branch Exec Source
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 101 static void log_to_stdout(void *avcl, int level, const char *fmt, va_list vl)
33 {
34
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 60 times.
101 if (level <= av_log_get_level())
35 41 vprintf(fmt, vl);
36 101 }
37
38 20 int main(int argc, char *argv[])
39 {
40 AVFormatContext *s;
41 20 ID3v2ExtraMeta *extra_meta = NULL;
42 20 const AVDictionaryEntry *tag = NULL;
43 int ret;
44
45 20 av_log_set_callback(log_to_stdout);
46
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (argc < 2) {
48 fprintf(stderr, "Usage: %s <file>\n", argv[0]);
49 return 1;
50 }
51
52 20 s = avformat_alloc_context();
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!s)
54 return 1;
55
56 20 s->debug |= AV_FDEBUG_ID3V2;
57
58 20 ret = avio_open(&s->pb, argv[1], AVIO_FLAG_READ);
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
60 fprintf(stderr, "Failed to open '%s'\n", argv[1]);
61 avformat_free_context(s);
62 return 1;
63 }
64
65 20 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &extra_meta, 0);
66
67
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 20 times.
61 while ((tag = av_dict_iterate(s->metadata, tag)))
68 41 printf("%s=%s\n", tag->key, tag->value);
69
70 20 ff_id3v2_free_extra_meta(&extra_meta);
71 20 avio_closep(&s->pb);
72 20 avformat_free_context(s);
73
74 20 return 0;
75 }
76