Skip to content

Commit

Permalink
Restructed ffmpeg calling
Browse files Browse the repository at this point in the history
  • Loading branch information
hidefuku committed Nov 22, 2016
1 parent dedfe66 commit 7c187dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@

# Build Directory
build*/

# Data
src/data/ffmpeg
12 changes: 8 additions & 4 deletions src/AnimeEffects.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ CONFIG += ordered
# copy directory
win32 {
copydata.commands = $(COPY_DIR) $$shell_path($$PWD/data) $$shell_path($$OUT_PWD/data)
first.depends = $(first) copydata
copytools.commands = $(COPY_DIR) $$shell_path($$PWD/../tools) $$shell_path($$OUT_PWD/tools)
first.depends = $(first) copydata copytools
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
export(copytools.commands)
QMAKE_EXTRA_TARGETS += first copydata copytools
}
unix {
copydata.commands = rsync -ru $$shell_path($$PWD/data) $$shell_path($$OUT_PWD)
first.depends = $(first) copydata
copytools.commands = rsync -ru $$shell_path($$PWD/../tools) $$shell_path($$OUT_PWD)
first.depends = $(first) copydata copytools
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
export(copytools.commands)
QMAKE_EXTRA_TARGETS += first copydata copytools
}
23 changes: 21 additions & 2 deletions src/ctrl/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Exporter::Exporter(core::Project& aProject)
, mVideoParam()
, mVideoExporting()
, mFFMpeg()
, mFFMpegErrorOccurred()
, mExporting(false)
, mIndex(0)
, mDigitCount(0)
Expand Down Expand Up @@ -124,12 +125,17 @@ bool Exporter::execute(const CommonParam& aCommon, const VideoParam& aVideo)
mVideoParam = aVideo;
mVideoExporting = true;
mOriginTimeInfo = mProject.currentTimeInfo();
mFFMpegErrorOccurred = false;

{
#if defined(_WIN32) || defined(_WIN64)
const QString program(".\\data\\ffmpeg\\bin\\ffmpeg.exe");
const QFileInfo localEncoderInfo("./tools/ffmpeg.exe");
const bool hasLocalEncoder = localEncoderInfo.exists() && localEncoderInfo.isExecutable();
const QString program = hasLocalEncoder ? QString(".\\tools\\ffmpeg") : QString("ffmpeg");
#else
const QString program("ffmpeg");
const QFileInfo localEncoderInfo("./tools/ffmpeg");
const bool hasLocalEncoder = localEncoderInfo.exists() && localEncoderInfo.isExecutable();
const QString program = hasLocalEncoder ? QString("./tools/ffmpeg") : QString("ffmpeg");
#endif
const QString out = " \"" + filePath.absoluteFilePath() + "\"";
const QString ifps = " -r " + QString::number(mCommonParam.fps);
Expand Down Expand Up @@ -159,7 +165,15 @@ bool Exporter::execute(const CommonParam& aCommon, const VideoParam& aVideo)
{
qDebug() << QString(process->readAll().data());
});
mFFMpeg->connect(process, &QProcess::errorOccurred, [=](QProcess::ProcessError aError)
{
qDebug() << "error occurred" << aError;
this->mFFMpegErrorOccurred = true;
});

mFFMpeg->start(command, QIODevice::ReadWrite);

if (mFFMpegErrorOccurred) return false;
}

return execute();
Expand Down Expand Up @@ -364,6 +378,11 @@ bool Exporter::exportImage(const QImage& aFboImage, int aIndex)
aFboImage.save(&buffer, "PNG");
buffer.close();
mFFMpeg->write(byteArray);

if (mFFMpegErrorOccurred)
{
return false;
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/ctrl/Exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Exporter
VideoParam mVideoParam;
bool mVideoExporting;
QScopedPointer<QProcess> mFFMpeg;
bool mFFMpegErrorOccurred;

bool mExporting;
int mIndex;
Expand Down
4 changes: 4 additions & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!*.exe

# ignore ffmpeg for license fear
ffmpeg*

0 comments on commit 7c187dd

Please sign in to comment.