- if (avcodec_open2 (codec_context, codec, 0) < 0) {
- throw DecodeError (N_("could not open decoder"));
+ auto context = avcodec_alloc_context3 (codec);
+ if (!context) {
+ throw DecodeError (N_("avcodec_alloc_context3"), name_for_errors, *_path);
+ }
+
+ r = avcodec_open2 (context, codec, 0);
+ if (r < 0) {
+ throw DecodeError (N_("avcodec_open2"), name_for_errors, r, *_path);