int main(void) { av_log_set_level(AV_LOG_TRACE); uint8_t *iframe; size_t iframe_sizem = 0; read_file("./iframe.raw", &iframe, &iframe_sizem); uint8_t *extradata = {0}; size_t extradata_size = 0; read_file("./extradata.raw", &extradata, &extradata_size); // Create codec parameters. AVCodecParameters *codec_params = avcodec_parameters_alloc(); codec_params->extradata = extradata; codec_params->extradata_size = extradata_size; AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264); if (!codec) { av_log(NULL, AV_LOG_ERROR, "Could not find decoder\n"); return -1; } // Create the codec context and initialize it with codec parameters AVCodecContext *codec_context = avcodec_alloc_context3(codec); if (!codec_context) { av_log(NULL, AV_LOG_ERROR, "Could not allocate the codec context\n"); return AVERROR(ENOMEM); } avcodec_parameters_to_context(codec_context, codec_params); printf("avcodec_open2()\n"); int ret; if ((ret = avcodec_open2(codec_context, codec, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Could not open video codec: %s\n", av_err2str(ret)); return ret; } // Packet must be allocated first. AVPacket *pkt = av_packet_alloc(); av_packet_from_data(pkt, iframe, iframe_sizem); AVFrame *frame = av_frame_alloc(); decode(codec_context, frame, pkt); }