summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-10-28 01:36:55 +0100
committerCarl Hetherington <cth@carlh.net>2024-11-01 01:40:30 +0100
commit8edadeea58faf5c075296df1f605407797e9a25a (patch)
tree1a0bc9496001db039c57741a2333ee038bcc9f34
parent738ced15ead0f029cf2becf9b77d7adf37e733e3 (diff)
Needing length is the same for audio and video, so merge them.
-rw-r--r--src/lib/ffmpeg.cc2
-rw-r--r--src/lib/ffmpeg_examiner.cc22
-rw-r--r--src/lib/ffmpeg_examiner.h3
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<shared_ptr<FFmpegAudioStream>> 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<const FFmpegContent> c, shared_ptr<Job> 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<const FFmpegContent> c, shared_ptr<Jo
s->codecpar->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<const FFmpegContent> c, shared_ptr<Jo
codec->name,
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<const FFmpegContent> c, shared_ptr<Jo
if (has_video ()) {
/* See if the header has duration information in it */
- _need_video_length = _format_context->duration == 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<FFmpegAudioStream> 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_ptr<FFmpegAudioStr
stream->first_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<double> _rotation;
bool _pulldown = false;