From 8edadeea58faf5c075296df1f605407797e9a25a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 28 Oct 2024 01:36:55 +0100 Subject: Needing length is the same for audio and video, so merge them. --- src/lib/ffmpeg.cc | 2 ++ src/lib/ffmpeg_examiner.cc | 22 ++++++++-------------- src/lib/ffmpeg_examiner.h | 3 +-- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index d9df232df..550e045b3 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -326,6 +326,8 @@ FFmpeg::pts_offset (vector> audio_streams, optiona } } + DCPOMATIC_ASSERT(po != ContentTime::min()); + /* If the offset is positive we would be pushing things from a -ve PTS to be played. I don't think we ever want to do that, as it seems things at -ve PTS are not meant to be seen (use for alignment bars etc.); see mantis #418. diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index 810a6eba2..3de1be888 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -63,6 +63,7 @@ static const int PULLDOWN_CHECK_FRAMES = 16; FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptr job) : FFmpeg (c) { + _need_length = _format_context->duration == AV_NOPTS_VALUE; /* Find audio and subtitle streams */ for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { @@ -78,10 +79,6 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrcodecpar->channel_layout = av_get_default_channel_layout (s->codecpar->channels); } - if (_format_context->duration == AV_NOPTS_VALUE) { - _need_audio_length = true; - } - DCPOMATIC_ASSERT (codec->name); _audio_streams.push_back ( @@ -90,7 +87,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrname, s->id, s->codecpar->sample_rate, - _need_audio_length ? 0 : rint ((double(_format_context->duration) / AV_TIME_BASE) * s->codecpar->sample_rate), + _need_length ? 0 : rint ((double(_format_context->duration) / AV_TIME_BASE) * s->codecpar->sample_rate), s->codecpar->channels, s->codecpar->bits_per_raw_sample ? s->codecpar->bits_per_raw_sample : s->codecpar->bits_per_coded_sample ) @@ -103,13 +100,10 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrduration == AV_NOPTS_VALUE; - if (!_need_video_length) { - _video_length = llrint ((double (_format_context->duration) / AV_TIME_BASE) * video_frame_rate().get()); - } + _video_length = _need_length ? 0 : llrint((double (_format_context->duration) / AV_TIME_BASE) * video_frame_rate().get()); } - if (job && _need_video_length) { + if (job && _need_length) { job->sub (_("Finding length")); } @@ -233,7 +227,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 * 2)) { + if (_first_video && !_need_length && temporal_reference.size() >= (PULLDOWN_CHECK_FRAMES * 2)) { return false; } @@ -260,7 +254,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context, string& temporal_referenc if (!_first_video) { _first_video = frame_time (_video_frame, _format_context->streams[_video_stream.get()]); } - if (_need_video_length) { + if (_need_length) { _video_length = frame_time( _video_frame, _format_context->streams[_video_stream.get()] @@ -278,7 +272,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context, string& temporal_referenc bool FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptr stream, AVPacket* packet) { - if (stream->first_audio && !_need_audio_length) { + if (stream->first_audio && !_need_length) { return false; } @@ -298,7 +292,7 @@ FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptrfirst_audio = frame_time(frame, stream->stream(_format_context)); } - if (_need_audio_length) { + if (_need_length) { stream->set_length(frame_time(frame, stream->stream(_format_context)).get_value_or({}).frames_round(stream->frame_rate()) + frame->nb_samples); } diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h index 57c97c542..ad64f349d 100644 --- a/src/lib/ffmpeg_examiner.h +++ b/src/lib/ffmpeg_examiner.h @@ -102,8 +102,7 @@ private: * through the whole file. */ Frame _video_length = 0; - bool _need_video_length = false; - bool _need_audio_length = false; + bool _need_length = false; boost::optional _rotation; bool _pulldown = false; -- cgit v1.2.3