Ignore audio streams with no codec, instead of crashing.
[dcpomatic.git] / src / lib / ffmpeg_examiner.cc
index 1a2c49f1cdfd66dcfd77e63f312255cbf4533be8..32b60e0cba53e61009019c5bd217fe57c8766304 100644 (file)
@@ -62,7 +62,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
 
        for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
                AVStream* s = _format_context->streams[i];
-               if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+               if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO && s->codec->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.
@@ -73,7 +73,6 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
                        }
 
                        DCPOMATIC_ASSERT (_format_context->duration != AV_NOPTS_VALUE);
-                       DCPOMATIC_ASSERT (s->codec->codec);
                        DCPOMATIC_ASSERT (s->codec->codec->name);
 
                        _audio_streams.push_back (
@@ -151,7 +150,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
 
                av_packet_unref (&_packet);
 
-               if (_first_video && got_all_audio && temporal_reference.size() >= PULLDOWN_CHECK_FRAMES) {
+               if (_first_video && got_all_audio && temporal_reference.size() >= (PULLDOWN_CHECK_FRAMES * 2)) {
                        /* All done */
                        break;
                }
@@ -177,12 +176,10 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
                }
 
                _rotation = *_rotation - 360 * floor (*_rotation / 360 + 0.9 / 360);
-
-               DCPOMATIC_ASSERT (fabs (*_rotation - 90 * round (*_rotation / 90)) < 2);
        }
 
        LOG_GENERAL("Temporal reference was %1", temporal_reference);
-       if (temporal_reference.find("T2T3B2B3T2T3B2B3") || temporal_reference.find("B2B3T2T3B2B3T2T3")) {
+       if (temporal_reference.find("T2T3B2B3T2T3B2B3") != string::npos || temporal_reference.find("B2B3T2T3B2B3T2T3") != string::npos) {
                /* The magical sequence (taken from mediainfo) suggests that 2:3 pull-down is in use */
                _pulldown = true;
                LOG_GENERAL_NC("Suggest that this may be 2:3 pull-down (soft telecine)");
@@ -206,7 +203,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context, string& temporal_referenc
 {
        DCPOMATIC_ASSERT (_video_stream);
 
-       if (_first_video && !_need_video_length && temporal_reference.size() >= PULLDOWN_CHECK_FRAMES) {
+       if (_first_video && !_need_video_length && temporal_reference.size() >= (PULLDOWN_CHECK_FRAMES * 2)) {
                return;
        }
 
@@ -220,7 +217,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context, string& temporal_referenc
                                _format_context->streams[_video_stream.get()]
                                ).get_value_or (ContentTime ()).frames_round (video_frame_rate().get ());
                }
-               if (temporal_reference.size() < PULLDOWN_CHECK_FRAMES) {
+               if (temporal_reference.size() < (PULLDOWN_CHECK_FRAMES * 2)) {
                        temporal_reference += (_frame->top_field_first ? "T" : "B");
                        temporal_reference += (_frame->repeat_pict ? "3" : "2");
                }