19 #include <QTextStream>
22 #include "fileformat.h"
23 #include "layercamera.h"
24 #include "layermanager.h"
25 #include "mainwindow2.h"
26 #include "movieexporter.h"
28 #include "playbackmanager.h"
30 #include "commandlineexporter.h"
33 mMainWindow(mainWindow),
49 LayerManager *layerManager = mMainWindow->mEditor->layers();
54 mErr <<
tr(
"Error: No input file specified.") << endl;
58 if (!inputFileInfo.
exists())
60 mErr <<
tr(
"Error: the input file at '%1' does not exist",
"Command line error").
arg(inputPath) << endl;
63 if (!inputFileInfo.
isFile())
65 mErr <<
tr(
"Error: the input path '%1' is not a file",
"Command line error").
arg(inputPath) << endl;
68 Q_ASSERT(!outputPaths.
empty());
70 mMainWindow->openFile(inputPath);
76 if (cameraLayer ==
nullptr)
78 mErr <<
tr(
"Warning: the specified camera layer %1 was not found, ignoring.").
arg(camera) << endl;
81 if (cameraLayer ==
nullptr)
84 Q_ASSERT(cameraLayer);
89 width = cameraLayer->getViewRect().
width();
93 height = cameraLayer->getViewRect().
height();
95 QSize exportSize(width, height);
97 Q_ASSERT(startFrame >= 1);
103 for (
const QString& outputPath : outputPaths)
106 QString format = detectFormatByFileNameExtension(outputPath);
109 mErr <<
tr(
"Warning: Output format is not specified or unsupported. Using PNG.",
"Command line warning") << endl;
113 if (isMovieFormat(format))
115 exportMovie(outputPath, cameraLayer, exportSize, startFrame, endFrame, transparency);
119 exportImageSequence(outputPath, format, cameraLayer, exportSize, startFrame, endFrame, transparency);
125 void CommandLineExporter::exportMovie(
const QString &outputPath,
127 const QSize &exportSize,
134 mErr <<
tr(
"Warning: Transparency is not currently supported in movie files",
"Command line warning") << endl;
137 mOut <<
tr(
"Exporting movie...",
"Command line task progress") <<
endl;
140 desc.strFileName = outputPath;
141 desc.startFrame = startFrame;
142 desc.endFrame = endFrame;
143 desc.fps = mMainWindow->mEditor->playback()->fps();
144 desc.exportSize = exportSize;
145 desc.strCameraName = cameraLayer->name();
148 ex.
run(mMainWindow->mEditor->object(), desc, [](float, float){}, [](float){}, [](
const QString &){});
149 mOut <<
tr(
"Done.",
"Command line task done") << endl;
152 void CommandLineExporter::exportImageSequence(
const QString &outputPath,
155 const QSize &exportSize,
160 mOut <<
tr(
"Exporting image sequence...",
"Command line task progress") << endl;
161 mMainWindow->mEditor->object()->exportFrames(startFrame,
173 mOut <<
tr(
"Done.",
"Command line task done") << endl;
CommandLineExporter(MainWindow2 *mainWindow)
Creates a new exporter instance.
QTextStream & endl(QTextStream &stream)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const const
bool isFile() const const
bool isEmpty() const const
Status run(const Object *obj, const ExportMovieDesc &desc, std::function< void(float, float)> majorProgress, std::function< void(float)> minorProgress, std::function< void(QString)> progressMessage)
Begin exporting the movie described by exportDesc.
bool exists() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool process(const QString &inputPath, const QStringList &outputPaths, const QString &camera, int width, int height, int startFrame, int endFrame, bool transparency)
Exports a Pencil2D file according to the specified options.
int animationLength(bool includeSounds=true)
Get the length of current project.
T qobject_cast(QObject *object)