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

Function video_decode_example

tests/api/api-h264-test.c:34–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include "libavutil/timestamp.h"
33
34static int video_decode_example(const char *input_filename)
35{
36 const AVCodec *codec = NULL;
37 AVCodecContext *ctx= NULL;
38 AVCodecParameters *origin_par = NULL;
39 AVFrame *fr = NULL;
40 uint8_t *byte_buffer = NULL;
41 AVPacket *pkt;
42 AVFormatContext *fmt_ctx = NULL;
43 int number_of_written_bytes;
44 int video_stream;
45 int byte_buffer_size;
46 int i = 0;
47 int result;
48
49 result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
50 if (result < 0) {
51 av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
52 return result;
53 }
54
55 result = avformat_find_stream_info(fmt_ctx, NULL);
56 if (result < 0) {
57 av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
58 return result;
59 }
60
61 video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
62 if (video_stream < 0) {
63 av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
64 return -1;
65 }
66
67 origin_par = fmt_ctx->streams[video_stream]->codecpar;
68
69 codec = avcodec_find_decoder(origin_par->codec_id);
70 if (!codec) {
71 av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
72 return -1;
73 }
74
75 ctx = avcodec_alloc_context3(codec);
76 if (!ctx) {
77 av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
78 return AVERROR(ENOMEM);
79 }
80
81 result = avcodec_parameters_to_context(ctx, origin_par);
82 if (result) {
83 av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
84 return result;
85 }
86
87 result = avcodec_open2(ctx, codec, NULL);
88 if (result < 0) {
89 av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
90 return result;
91 }

Callers 1

mainFunction · 0.85

Calls 15

avformat_open_inputFunction · 0.85
av_logFunction · 0.85
av_find_best_streamFunction · 0.85
avcodec_find_decoderFunction · 0.85
avcodec_alloc_context3Function · 0.85
avcodec_open2Function · 0.85
av_frame_allocFunction · 0.85
av_packet_allocFunction · 0.85
av_image_get_buffer_sizeFunction · 0.85
av_read_frameFunction · 0.85

Tested by

no test coverage detected