From 2d57f22f3a9eb3cfc0eaf64743592b82440c361e Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 9 Mar 2020 20:08:05 +1100 Subject: [PATCH] oiiodecoder: implemented heuristic to auto-detect start and end index --- app/codec/oiio/oiiodecoder.cpp | 33 +++++++++++++++++++++++++++++---- app/codec/oiio/oiiodecoder.h | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/codec/oiio/oiiodecoder.cpp b/app/codec/oiio/oiiodecoder.cpp index 6f62bc6c9..f4a1e33f3 100644 --- a/app/codec/oiio/oiiodecoder.cpp +++ b/app/codec/oiio/oiiodecoder.cpp @@ -86,11 +86,23 @@ bool OIIODecoder::Probe(Footage *f, const QAtomicInt *cancelled) video_stream->set_frame_rate(default_timebase.flipped()); video_stream->set_image_sequence(true); - // FIXME: Get actual start number - video_stream->set_start_time(1); + int64_t seq_index = GetImageSequenceIndex(f->filename()); - // FIXME: Get actual duration - video_stream->set_duration(200); + int64_t start_index = seq_index; + int64_t end_index = seq_index; + + // Heuristic to find the first and last images (users can always override this later in FootagePropertiesDialog) + while (QFileInfo::exists(TransformImageSequenceFileName(f->filename(), start_index-1))) { + start_index--; + } + + while (QFileInfo::exists(TransformImageSequenceFileName(f->filename(), end_index+1))) { + end_index++; + } + + video_stream->set_start_time(start_index); + + video_stream->set_duration(end_index - start_index); } else { image_stream = std::make_shared(); } @@ -261,6 +273,19 @@ QString OIIODecoder::TransformImageSequenceFileName(const QString &filename, con return file_info.dir().filePath(file_info.fileName().replace(original_basename, new_basename)); } +int64_t OIIODecoder::GetImageSequenceIndex(const QString &filename) +{ + int digit_count = GetImageSequenceDigitCount(filename); + + QFileInfo file_info(filename); + + QString original_basename = file_info.baseName(); + + QString number_only = original_basename.mid(original_basename.size() - digit_count); + + return number_only.toLongLong(); +} + bool OIIODecoder::OpenImageHandler(const QString &fn) { image_ = OIIO::ImageInput::open(fn.toStdString()); diff --git a/app/codec/oiio/oiiodecoder.h b/app/codec/oiio/oiiodecoder.h index f4eff4db6..657758bd8 100644 --- a/app/codec/oiio/oiiodecoder.h +++ b/app/codec/oiio/oiiodecoder.h @@ -58,6 +58,8 @@ private: static QString TransformImageSequenceFileName(const QString& filename, const int64_t& number); + static int64_t GetImageSequenceIndex(const QString& filename); + bool OpenImageHandler(const QString& fn); void CloseImageHandle();