From 9d012faf9d8e7fca7e041f852201dd9f6ae3598c Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Sun, 10 Sep 2023 13:25:09 +0200 Subject: [PATCH 1/3] pass 'start_number' to player for dpx --- Source/Core/FileInformation.cpp | 11 ++++++++--- Source/Core/FileInformation.h | 2 +- Source/GUI/Comments.h | 2 +- Source/GUI/player.h | 11 +++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/Core/FileInformation.cpp b/Source/Core/FileInformation.cpp index 5af0b23cf..483b46c90 100644 --- a/Source/Core/FileInformation.cpp +++ b/Source/Core/FileInformation.cpp @@ -574,13 +574,15 @@ bool isDpx(QString mediaFileName) { return mediaFileName.endsWith(dotDpx, Qt::CaseInsensitive); } -QString adjustDpxFileName(QString mediaFileName) { +QString adjustDpxFileName(QString mediaFileName, int& dpxOffset) { auto offset = mediaFileName.length() - dotDpx.length() - 1; auto numberOfDigits = 0; while(offset >= 0 && mediaFileName[offset].isNumber()) { --offset; ++numberOfDigits; } + + dpxOffset = mediaFileName.mid(offset + 1, numberOfDigits).toInt(); auto fmt = QString::asprintf("%0%dd", numberOfDigits); mediaFileName.replace(offset + 1, numberOfDigits, fmt); @@ -796,13 +798,16 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil } } + m_mediaParser = new QAVPlayer(); + if(mediaFileName == "-") mediaFileName = "pipe:0"; else if(isDpx(mediaFileName)) { - mediaFileName = adjustDpxFileName(mediaFileName); + int dpxOffset = 0; + mediaFileName = adjustDpxFileName(mediaFileName, dpxOffset); + m_mediaParser->setInputOptions({ {"start_number", QString::number(dpxOffset) } }); } - m_mediaParser = new QAVPlayer(); m_mediaParser->setSource(mediaFileName); m_mediaParser->setSynced(false); diff --git a/Source/Core/FileInformation.h b/Source/Core/FileInformation.h index cfbab198d..24edb9c69 100644 --- a/Source/Core/FileInformation.h +++ b/Source/Core/FileInformation.h @@ -38,7 +38,7 @@ std::string FFmpeg_Configuration(); std::string FFmpeg_LibsVersion(); bool isDpx(QString mediaFileName); -QString adjustDpxFileName(QString mediaFileName); +QString adjustDpxFileName(QString mediaFileName, int& dpxOffset); //--------------------------------------------------------------------------- class FileInformation : public QThread diff --git a/Source/GUI/Comments.h b/Source/GUI/Comments.h index f2fd5a1d0..612e1c2e2 100644 --- a/Source/GUI/Comments.h +++ b/Source/GUI/Comments.h @@ -37,7 +37,7 @@ class CommentsSeriesData : public QwtPointSeriesData } size_t size() const { - return stats->x_Current; + return stats ? stats->x_Current : 0; } QPointF sample(size_t i) const { int dataTypeIndex = pDataTypeIndex ? *pDataTypeIndex : 0; diff --git a/Source/GUI/player.h b/Source/GUI/player.h index 06ca4ec8a..d94416332 100644 --- a/Source/GUI/player.h +++ b/Source/GUI/player.h @@ -132,8 +132,15 @@ class MediaPlayer : public QAVPlayer { m_file = file; auto sourceFile = m_file; - if(isDpx(sourceFile)) - sourceFile = adjustDpxFileName(sourceFile); + if (isDpx(sourceFile)) { + int dpxOffset = 0; + sourceFile = adjustDpxFileName(sourceFile, dpxOffset); + setInputOptions({ {"start_number", QString::number(dpxOffset) } }); + } else { + if(!inputOptions().empty()) { + setInputOptions({}); + } + } setSource(sourceFile); } From 55ae2127072a66032bc7da88ef7fcb2f664449cf Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Sun, 10 Sep 2023 14:18:00 +0200 Subject: [PATCH 2/3] prepare dpx fmt string based on the first dpx filename --- Source/Core/FileInformation.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Core/FileInformation.cpp b/Source/Core/FileInformation.cpp index 483b46c90..449bc1ba6 100644 --- a/Source/Core/FileInformation.cpp +++ b/Source/Core/FileInformation.cpp @@ -582,7 +582,28 @@ QString adjustDpxFileName(QString mediaFileName, int& dpxOffset) { ++numberOfDigits; } + QFileInfo info(mediaFileName); + QDir dir(info.absolutePath()); + dpxOffset = mediaFileName.mid(offset + 1, numberOfDigits).toInt(); + auto dpxWildcard = mediaFileName; + + dpxWildcard.replace(offset + 1, numberOfDigits, "*"); + dpxWildcard.remove(0, info.absolutePath().size() + 1); + + auto entries = dir.entryList(QStringList() << dpxWildcard, QDir::Files, QDir::Name); + if (!entries.empty()) { + auto firstEntry = entries[0]; + mediaFileName.replace(mediaFileName.size() - info.fileName().size(), info.fileName().length(), firstEntry); + + offset = mediaFileName.length() - dotDpx.length() - 1; + numberOfDigits = 0; + while (offset >= 0 && mediaFileName[offset].isNumber()) { + --offset; + ++numberOfDigits; + } + } + auto fmt = QString::asprintf("%0%dd", numberOfDigits); mediaFileName.replace(offset + 1, numberOfDigits, fmt); From b907b83d83e35f5ce69cee5ecb97723b850bee9f Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Mon, 11 Sep 2023 18:00:28 +0200 Subject: [PATCH 3/3] add '-f image2' to dpx-handling codepath --- Source/Core/FileInformation.cpp | 15 ++++++++++++--- Source/GUI/player.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Core/FileInformation.cpp b/Source/Core/FileInformation.cpp index 449bc1ba6..3fce1663a 100644 --- a/Source/Core/FileInformation.cpp +++ b/Source/Core/FileInformation.cpp @@ -821,12 +821,12 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil m_mediaParser = new QAVPlayer(); + int dpxOffset = -1; if(mediaFileName == "-") mediaFileName = "pipe:0"; else if(isDpx(mediaFileName)) { - int dpxOffset = 0; mediaFileName = adjustDpxFileName(mediaFileName, dpxOffset); - m_mediaParser->setInputOptions({ {"start_number", QString::number(dpxOffset) } }); + m_mediaParser->setInputOptions({ {"start_number", QString::number(dpxOffset) }, {"f", "image2"} }); } m_mediaParser->setSource(mediaFileName); @@ -860,7 +860,13 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil AVFormatContext* FormatContext = nullptr; auto stdMediaFileName = mediaFileName.toStdString(); - if (avformat_open_input(&FormatContext, stdMediaFileName.c_str(), NULL, NULL)>=0) + AVDictionary* options = nullptr; + if (dpxOffset != -1) { + auto dpxOffsetString = std::to_string(dpxOffset); + av_dict_set(&options, "f", "image2", 0); + av_dict_set(&options, "start_number", dpxOffsetString.c_str(), 0); + } + if (avformat_open_input(&FormatContext, stdMediaFileName.c_str(), nullptr, &options)>=0) { QVector orderedStreams; if (avformat_find_stream_info(FormatContext, NULL)>=0) { @@ -931,6 +937,9 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil avformat_close_input(&FormatContext); } + if (options) { + av_dict_free(&options); + } } if(attachment.isEmpty()) { diff --git a/Source/GUI/player.h b/Source/GUI/player.h index d94416332..7c9cbd9b4 100644 --- a/Source/GUI/player.h +++ b/Source/GUI/player.h @@ -135,7 +135,7 @@ class MediaPlayer : public QAVPlayer { if (isDpx(sourceFile)) { int dpxOffset = 0; sourceFile = adjustDpxFileName(sourceFile, dpxOffset); - setInputOptions({ {"start_number", QString::number(dpxOffset) } }); + setInputOptions({ {"start_number", QString::number(dpxOffset) }, {"f", "image2"} }); } else { if(!inputOptions().empty()) { setInputOptions({});