From 1ae3b877a12fea013e41d559869aa560a41debd8 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 26 Feb 2019 10:58:55 -0800 Subject: [PATCH] find starting number for image sequences automatically --- io/loadthread.cpp | 2 ++ io/previewgenerator.cpp | 10 +++++++++- io/proxygenerator.cpp | 8 +++++++- panels/project.cpp | 17 +++++++++++++++++ project/footage.cpp | 21 +++++++++++---------- project/footage.h | 1 + rendering/cacher.cpp | 8 +++++++- 7 files changed, 54 insertions(+), 13 deletions(-) diff --git a/io/loadthread.cpp b/io/loadthread.cpp index fae123a19..b6e96123e 100644 --- a/io/loadthread.cpp +++ b/io/loadthread.cpp @@ -290,6 +290,8 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) { f->proxy = (attr.value() == "1"); } else if (attr.name() == "proxypath") { f->proxy_path = attr.value().toString(); + } else if (attr.name() == "startnumber") { + f->start_number = attr.value().toInt(); } } diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index b5f0a94ef..fabc2e5c2 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -524,7 +524,15 @@ void PreviewGenerator::run() { QString errorStr; bool error = false; - int errCode = avformat_open_input(&fmt_ctx_, filename, nullptr, nullptr); + + AVDictionary* format_opts = nullptr; + + // for image sequences that don't start at 0, set the index where it does start + if (footage_->start_number > 0) { + av_dict_set(&format_opts, "start_number", QString::number(footage_->start_number).toUtf8(), 0); + } + + int errCode = avformat_open_input(&fmt_ctx_, filename, nullptr, &format_opts); if(errCode != 0) { char err[1024]; av_strerror(errCode, err, 1024); diff --git a/io/proxygenerator.cpp b/io/proxygenerator.cpp index 58251ac45..9bba533a2 100644 --- a/io/proxygenerator.cpp +++ b/io/proxygenerator.cpp @@ -47,9 +47,15 @@ void ProxyGenerator::transcode(const ProxyInfo& info) { // set progress to 0 current_progress = 0.0; + // for image sequences that don't start at 0, set the index where it does start + AVDictionary* format_opts = nullptr; + if (footage->start_number > 0) { + av_dict_set(&format_opts, "start_number", QString::number(footage->start_number).toUtf8(), 0); + } + // open input file AVFormatContext* input_fmt_ctx = nullptr; - avformat_open_input(&input_fmt_ctx, footage->url.toUtf8(), nullptr, nullptr); + avformat_open_input(&input_fmt_ctx, footage->url.toUtf8(), nullptr, &format_opts); // open output file AVFormatContext* output_fmt_ctx = nullptr; diff --git a/panels/project.cpp b/panels/project.cpp index 786f6e82d..dbfd76d6c 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -740,7 +740,11 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla if (lastcharindex == 0) lastcharindex++; + // used for image sequences that don't start at "0" + int start_number = 0; + if (found && file[lastcharindex-1].isDigit()) { + bool is_img_sequence = false; // how many digits are in the filename? @@ -787,6 +791,17 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla QMessageBox::Yes) == QMessageBox::Yes) { file = new_filename; image_sequence_importassequence.append(true); + + + // try to find the start number for this image sequence + int test_file_number = file_number; + do { + test_file_number--; + } while (QFileInfo::exists(QString("%1%2%3").arg(file.left(digit_test), + QString("%1").arg(test_file_number, digit_count, 10, QChar('0')), + file.mid(lastcharindex)))); + start_number = test_file_number + 1; + } else { image_sequence_importassequence.append(false); } @@ -809,6 +824,7 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla m->using_inout = false; m->url = file; m->name = get_file_name_from_path(files.at(i)); + m->start_number = start_number; item->set_footage(m); @@ -1028,6 +1044,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only, stream.writeAttribute("out", QString::number(f->out)); stream.writeAttribute("speed", QString::number(f->speed)); stream.writeAttribute("alphapremul", QString::number(f->alpha_is_premultiplied)); + stream.writeAttribute("startnumber", QString::number(f->start_number)); stream.writeAttribute("proxy", QString::number(f->proxy)); stream.writeAttribute("proxypath", f->proxy_path); diff --git a/project/footage.cpp b/project/footage.cpp index 52da3bb7d..b7e7f5a28 100644 --- a/project/footage.cpp +++ b/project/footage.cpp @@ -27,16 +27,17 @@ #include "project/clip.h" -Footage::Footage() : - ready(false), - preview_gen(nullptr), - invalid(false), - in(0), - out(0), - speed(1.0), - alpha_is_premultiplied(false), - proxy(false) -{ +Footage::Footage() { + ready = (false); + preview_gen = (nullptr); + invalid = (false); + in = (0); + out = (0); + speed = (1.0); + alpha_is_premultiplied = (false); + proxy = (false); + start_number = 0; + ready_lock.lock(); } diff --git a/project/footage.h b/project/footage.h index 5f158f0e0..ffbd1a001 100644 --- a/project/footage.h +++ b/project/footage.h @@ -82,6 +82,7 @@ struct Footage { bool invalid; double speed; bool alpha_is_premultiplied; + int start_number; // proxy config bool proxy; diff --git a/rendering/cacher.cpp b/rendering/cacher.cpp index 47b8e9c97..8081dc228 100644 --- a/rendering/cacher.cpp +++ b/rendering/cacher.cpp @@ -781,12 +781,18 @@ void Cacher::OpenWorker() { const char* filename = ba.constData(); const FootageStream* ms = clip->media_stream(); + // for image sequences that don't start at 0, set the index where it does start + AVDictionary* format_opts = nullptr; + if (m->start_number > 0) { + av_dict_set(&format_opts, "start_number", QString::number(m->start_number).toUtf8(), 0); + } + formatCtx = nullptr; int errCode = avformat_open_input( &formatCtx, filename, nullptr, - nullptr + &format_opts ); if (errCode != 0) { char err[1024];