@@ -32,6 +32,7 @@ extern AVCodec ff_hevc_decoder;
32
32
extern AVCodec ff_mpeg4_decoder;
33
33
extern AVCodec ff_vp9_decoder;
34
34
extern AVCodec ff_vp8_decoder;
35
+ extern AVCodec ff_av1_decoder;
35
36
extern AVCodec ff_mp3_decoder;
36
37
extern AVCodec ff_flac_decoder;
37
38
extern AVCodec ff_aac_decoder;
@@ -243,6 +244,9 @@ avcodec_decoder avcodec_decoder_create(const opencv_mat buf, const bool hevc_ena
243
244
const AVCodec* libaom_codec = avcodec_find_decoder_by_name (" libaom-av1" );
244
245
if (libaom_codec) {
245
246
codec = libaom_codec;
247
+ } else {
248
+ // If no named decoder found, try the direct codec lookup
249
+ codec = avcodec_find_decoder (AV_CODEC_ID_AV1);
246
250
}
247
251
}
248
252
}
@@ -366,9 +370,22 @@ int avcodec_decoder_get_orientation(const avcodec_decoder d)
366
370
rotation = atoi (tag->value );
367
371
}
368
372
else {
369
- // For now, skip display matrix rotation detection to avoid deprecated API
370
- // Most rotation information is available via metadata tags above
371
- rotation = 0 ;
373
+ uint8_t * displaymatrix = NULL ;
374
+ const AVPacketSideData* sd = NULL ;
375
+
376
+ // access side data from codecpar instead of directly from the stream
377
+ AVCodecParameters* codecpar = d->container ->streams [d->video_stream_index ]->codecpar ;
378
+ for (int i = 0 ; i < codecpar->nb_coded_side_data ; i++) {
379
+ if (codecpar->coded_side_data [i].type == AV_PKT_DATA_DISPLAYMATRIX) {
380
+ sd = &codecpar->coded_side_data [i];
381
+ break ;
382
+ }
383
+ }
384
+
385
+ displaymatrix = sd ? sd->data : NULL ;
386
+ if (displaymatrix) {
387
+ rotation = (360 - (int )(av_display_rotation_get ((const int32_t *)displaymatrix))) % 360 ;
388
+ }
372
389
}
373
390
switch (rotation) {
374
391
case 90 :
@@ -442,6 +459,11 @@ static int avcodec_decoder_copy_frame(const avcodec_decoder d, opencv_mat mat, A
442
459
return -1 ;
443
460
}
444
461
462
+ // Extra safety check for AV1 decoder context
463
+ if (!d->codec ->codec || !d->codec ->codec ->decode ) {
464
+ return AVERROR (EINVAL);
465
+ }
466
+
445
467
int res = avcodec_receive_frame (d->codec , frame);
446
468
if (res >= 0 ) {
447
469
// Calculate the step size based on the cv::Mat's width
0 commit comments