@@ -39,7 +39,7 @@ extern AVCodec ff_vorbis_decoder;
3939
4040void avcodec_init ()
4141{
42- av_log_set_level (AV_LOG_INFO );
42+ av_log_set_level (AV_LOG_ERROR );
4343}
4444
4545struct avcodec_decoder_struct {
@@ -228,7 +228,6 @@ avcodec_decoder avcodec_decoder_create(const opencv_mat buf, const bool hevc_ena
228228 }
229229
230230 const AVCodec* codec = avcodec_find_decoder (codec_params->codec_id );
231-
232231 if (!codec) {
233232 avcodec_decoder_release (d);
234233 return NULL ;
@@ -252,16 +251,6 @@ avcodec_decoder avcodec_decoder_create(const opencv_mat buf, const bool hevc_ena
252251 return NULL ;
253252 }
254253
255- // Configure AV1 decoder for software-only decoding
256- if (codec->id == AV_CODEC_ID_AV1) {
257- // Explicitly disable hardware acceleration to prevent format errors
258- d->codec ->hw_device_ctx = NULL ;
259- d->codec ->hwaccel_context = NULL ;
260- d->codec ->hwaccel = NULL ;
261- d->codec ->get_format = NULL ; // Use default software format selection
262- d->codec ->thread_count = 0 ; // Let FFmpeg choose optimal thread count
263- }
264-
265254 res = avcodec_open2 (d->codec , codec, NULL );
266255 if (res < 0 ) {
267256 avcodec_decoder_release (d);
@@ -348,11 +337,16 @@ int avcodec_decoder_get_orientation(const avcodec_decoder d)
348337 }
349338 else {
350339 uint8_t * displaymatrix = NULL ;
351- size_t side_data_size = 0 ;
352-
353- // Get side data from stream
354- AVStream* stream = d->container ->streams [d->video_stream_index ];
355- displaymatrix = av_stream_get_side_data (stream, AV_PKT_DATA_DISPLAYMATRIX, &side_data_size);
340+ const AVPacketSideData* sd = NULL ;
341+
342+ // access side data from codecpar instead of directly from the stream
343+ AVCodecParameters* codecpar = d->container ->streams [d->video_stream_index ]->codecpar ;
344+ for (int i = 0 ; i < codecpar->nb_coded_side_data ; i++) {
345+ if (codecpar->coded_side_data [i].type == AV_PKT_DATA_DISPLAYMATRIX) {
346+ sd = &codecpar->coded_side_data [i];
347+ break ;
348+ }
349+ }
356350
357351 if (displaymatrix) {
358352 rotation = (360 - (int )(av_display_rotation_get ((const int32_t *)displaymatrix))) % 360 ;
@@ -421,7 +415,7 @@ bool avcodec_decoder_has_subtitles(const avcodec_decoder d)
421415
422416static int avcodec_decoder_copy_frame (const avcodec_decoder d, opencv_mat mat, AVFrame* frame)
423417{
424- if (!d || !d->codec || !mat || !frame) {
418+ if (!d || !d->codec || !d-> codec -> codec || ! mat || !frame) {
425419 return -1 ;
426420 }
427421
@@ -430,11 +424,6 @@ static int avcodec_decoder_copy_frame(const avcodec_decoder d, opencv_mat mat, A
430424 return -1 ;
431425 }
432426
433- // Extra safety check for AV1 decoder context
434- if (!d->codec ->codec ) {
435- return AVERROR (EINVAL);
436- }
437-
438427 int res = avcodec_receive_frame (d->codec , frame);
439428 if (res >= 0 ) {
440429 // Calculate the step size based on the cv::Mat's width
@@ -527,18 +516,10 @@ static int avcodec_decoder_decode_packet(const avcodec_decoder d, opencv_mat mat
527516
528517bool avcodec_decoder_decode (const avcodec_decoder d, opencv_mat mat)
529518{
530- if (!d) {
531- return false ;
532- }
533- if (!d->container ) {
534- return false ;
535- }
536- if (!d->codec ) {
537- return false ;
538- }
539- if (!mat) {
519+ if (!d || !d->container || !d->codec || !mat) {
540520 return false ;
541521 }
522+
542523 AVPacket packet;
543524 bool done = false ;
544525 bool success = false ;
0 commit comments