- /* get a pointer to the codec context for the video stream */
- input_codec_ctx = input_format_ctx->streams[video_index]->codec;
-
- /* find the decoder for the video stream */
- input_codec = avcodec_find_decoder(input_codec_ctx->codec_id);
- if (input_codec == NULL) {
- fprintf(stderr, "input_codec is NULL!\n");
- ret = -EINVAL;
+ input_codec_ctx = avcodec_alloc_context3(input_codec);
+ if (input_codec_ctx == NULL) {
+ fprintf(stderr, "failed to allocate the input codec context\n");
+ ret = -ENOMEM;