MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / dump_stream_meta

Function dump_stream_meta

tests/api/api-dump-stream-meta-test.c:31–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#include "libavutil/timestamp.h"
30
31static int dump_stream_meta(const char *input_filename) {
32 const AVCodec *codec = NULL;
33 AVPacket *pkt = NULL;
34 AVFrame *fr = NULL;
35 AVFormatContext *fmt_ctx = NULL;
36 AVCodecContext *ctx = NULL;
37 AVCodecParameters *origin_par = NULL;
38 AVStream *st;
39 int stream_idx = 0;
40 int result;
41 char *metadata;
42
43 result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
44 if (result < 0) {
45 av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
46 return result;
47 }
48
49 result = avformat_find_stream_info(fmt_ctx, NULL);
50 if (result < 0) {
51 av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
52 goto end;
53 }
54
55 if (fmt_ctx->nb_streams > 1) {
56 av_log(NULL, AV_LOG_ERROR, "More than one stream found in input!\n");
57 goto end;
58 }
59
60 origin_par = fmt_ctx->streams[stream_idx]->codecpar;
61 st = fmt_ctx->streams[stream_idx];
62
63 result = av_dict_get_string(st->metadata, &metadata, '=', ':');
64 if (result < 0)
65 goto end;
66
67 printf("Stream ID: %d, codec name: %s, metadata: %s\n", stream_idx,
68 avcodec_get_name(origin_par->codec_id),
69 strlen(metadata) ? metadata : "N/A");
70 av_free(metadata);
71
72 codec = avcodec_find_decoder(origin_par->codec_id);
73 if (!codec) {
74 av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
75 result = AVERROR_DECODER_NOT_FOUND;
76 goto end;
77 }
78
79 ctx = avcodec_alloc_context3(codec);
80 if (!ctx) {
81 av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
82 result = AVERROR(ENOMEM);
83 goto end;
84 }
85
86 result = avcodec_parameters_to_context(ctx, origin_par);
87 if (result) {
88 av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");

Callers 1

mainFunction · 0.85

Calls 15

avformat_open_inputFunction · 0.85
av_logFunction · 0.85
av_dict_get_stringFunction · 0.85
avcodec_get_nameFunction · 0.85
avcodec_find_decoderFunction · 0.85
avcodec_alloc_context3Function · 0.85
avcodec_open2Function · 0.85
av_packet_allocFunction · 0.85
av_frame_allocFunction · 0.85
av_read_frameFunction · 0.85

Tested by

no test coverage detected