diff --git a/Source/Core/FileInformation.cpp b/Source/Core/FileInformation.cpp index 5af0b23cf..3fce1663a 100644 --- a/Source/Core/FileInformation.cpp +++ b/Source/Core/FileInformation.cpp @@ -574,13 +574,36 @@ 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; } + + 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); @@ -796,13 +819,16 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil } } + m_mediaParser = new QAVPlayer(); + + int dpxOffset = -1; if(mediaFileName == "-") mediaFileName = "pipe:0"; else if(isDpx(mediaFileName)) { - mediaFileName = adjustDpxFileName(mediaFileName); + mediaFileName = adjustDpxFileName(mediaFileName, dpxOffset); + m_mediaParser->setInputOptions({ {"start_number", QString::number(dpxOffset) }, {"f", "image2"} }); } - m_mediaParser = new QAVPlayer(); m_mediaParser->setSource(mediaFileName); m_mediaParser->setSynced(false); @@ -834,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) { @@ -905,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/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..7c9cbd9b4 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) }, {"f", "image2"} }); + } else { + if(!inputOptions().empty()) { + setInputOptions({}); + } + } setSource(sourceFile); }