Skip to content

Commit

Permalink
Merge pull request #803 from ElderOrb/dpx_offset
Browse files Browse the repository at this point in the history
Pass dpx offset to the player
  • Loading branch information
dericed authored Sep 12, 2023
2 parents a7aff0f + b907b83 commit 6856ab3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
43 changes: 39 additions & 4 deletions Source/Core/FileInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<QAVStream*> orderedStreams;
if (avformat_find_stream_info(FormatContext, NULL)>=0) {
Expand Down Expand Up @@ -905,6 +937,9 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil

avformat_close_input(&FormatContext);
}
if (options) {
av_dict_free(&options);
}
}

if(attachment.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/FileInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/GUI/Comments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions Source/GUI/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6856ab3

Please sign in to comment.