| 32 | #include "libavutil/timestamp.h" |
| 33 | |
| 34 | static 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 | } |
no test coverage detected