Merge remote-tracking branch 'origin/main' into v2.17.x
authorCarl Hetherington <cth@carlh.net>
Fri, 29 Mar 2024 23:00:44 +0000 (00:00 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 29 Mar 2024 23:00:44 +0000 (00:00 +0100)
1  2 
src/lib/ffmpeg_examiner.cc

index f7d3f9df334b8d92f00c93adc456c08b587cec30,51ade8e89cb844336baa4dfac51ef56be3f4fbea..d173c6bb660cd12415285721bad4f068e68a982f
@@@ -73,6 -73,14 +73,6 @@@ FFmpegExaminer::FFmpegExaminer (shared_
                auto codec = _codec_context[i] ? _codec_context[i]->codec : nullptr;
                if (s->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && codec) {
  
 -                      /* This is a hack; sometimes it seems that _audio_codec_context->channel_layout isn't set up,
 -                         so bodge it here.  No idea why we should have to do this.
 -                      */
 -
 -                      if (s->codecpar->channel_layout == 0) {
 -                              s->codecpar->channel_layout = av_get_default_channel_layout (s->codecpar->channels);
 -                      }
 -
                        DCPOMATIC_ASSERT (_format_context->duration != AV_NOPTS_VALUE);
                        DCPOMATIC_ASSERT (codec->name);
  
@@@ -83,7 -91,7 +83,7 @@@
                                        s->id,
                                        s->codecpar->sample_rate,
                                        llrint ((double(_format_context->duration) / AV_TIME_BASE) * s->codecpar->sample_rate),
 -                                      s->codecpar->channels,
 +                                      s->codecpar->ch_layout.nb_channels,
                                        s->codecpar->bits_per_raw_sample ? s->codecpar->bits_per_raw_sample : s->codecpar->bits_per_coded_sample
                                        )
                                );
  
                av_packet_free (&packet);
  
 -              if (_first_video && got_all_audio && temporal_reference.size() >= (PULLDOWN_CHECK_FRAMES * 2)) {
 +              if (got_all_audio && (!_video_stream || (_first_video && temporal_reference.size() >= (PULLDOWN_CHECK_FRAMES * 2)))) {
                        /* All done */
                        break;
                }
                /* This code taken from get_rotation() in ffmpeg:cmdutils.c */
                auto stream = _format_context->streams[*_video_stream];
                auto rotate_tag = av_dict_get (stream->metadata, "rotate", 0, 0);
 -              uint8_t* displaymatrix = av_stream_get_side_data (stream, AV_PKT_DATA_DISPLAYMATRIX, 0);
 -
                if (rotate_tag && *rotate_tag->value && strcmp(rotate_tag->value, "0")) {
                        char *tail;
                        _rotation = av_strtod (rotate_tag->value, &tail);
                        }
                }
  
 -              if (displaymatrix && !_rotation) {
 -                      _rotation = - av_display_rotation_get ((int32_t*) displaymatrix);
 +              auto side_data = av_packet_side_data_get(stream->codecpar->coded_side_data, stream->codecpar->nb_coded_side_data, AV_PKT_DATA_DISPLAYMATRIX);
 +              if (side_data && !_rotation) {
 +                      _rotation = - av_display_rotation_get(reinterpret_cast<int32_t*>(side_data->data));
                }
  
-               _rotation = *_rotation - 360 * floor (*_rotation / 360 + 0.9 / 360);
+               if (_rotation) {
+                       _rotation = *_rotation - 360 * floor (*_rotation / 360 + 0.9 / 360);
+               }
        }
  
        LOG_GENERAL("Temporal reference was %1", temporal_reference);
@@@ -242,7 -253,7 +244,7 @@@ FFmpegExaminer::video_packet (AVCodecCo
                        ).get_value_or (ContentTime ()).frames_round (video_frame_rate().get ());
        }
        if (temporal_reference.size() < (PULLDOWN_CHECK_FRAMES * 2)) {
 -              temporal_reference += (_video_frame->top_field_first ? "T" : "B");
 +              temporal_reference += ((_video_frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? "T" : "B");
                temporal_reference += (_video_frame->repeat_pict ? "3" : "2");
        }