Ticket #10364: flac_chained_metadata.c

File flac_chained_metadata.c, 1.4 KB (added by toots, 4 years ago)
Line 
1#include <stdio.h>
2#include <libavformat/avformat.h>
3#include <libavutil/opt.h>
4
5int main(int argc, char **argv) {
6 const char *filename;
7 AVFormatContext *format_context = NULL;
8 AVFrame *frame = NULL;
9 AVStream *stream;
10 AVPacket *packet = NULL;
11 AVDictionaryEntry *tag = NULL;
12 int ret;
13
14 if (argc <= 1) {
15 fprintf(stderr, "Usage: %s <input url>\n", argv[0]);
16 exit(0);
17 }
18
19 filename = argv[1];
20 const AVInputFormat *format = av_find_input_format("ogg");
21 AVDictionary *options = NULL;
22 ret = avformat_open_input(&format_context, filename, format, &options);
23 if (ret < 0) {
24 fprintf(stderr, "Could not open %s: %s\n", filename, av_err2str(ret));
25 exit(1);
26 }
27
28 ret = avformat_find_stream_info(format_context, 0);
29 if (ret < 0) {
30 fprintf(stderr, "Failed to retrieve input stream information: %s\n", av_err2str(ret));
31 exit(1);
32 }
33
34 av_dump_format(format_context, 0, argv[0], 0);
35
36 stream = format_context->streams[0];
37
38 packet = av_packet_alloc();
39 if (!packet) {
40 fprintf(stderr, "Could not allocate packet\n");
41 exit(1);
42 }
43
44 printf("Reading from: %s\n", filename);
45 while (av_read_frame(format_context, packet) >= 0) {
46 av_packet_unref(packet);
47
48 while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
49 printf("%s=%s\n", tag->key, tag->value);
50 }
51 }
52end:
53 avformat_close_input(&format_context);
54 av_packet_free(&packet);
55
56 return 0;
57}