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"
32#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
35const auto qEndl =
endl;
59 mErr <<
tr(
"Error: No input file specified. An input project file argument is required when output path(s) are specified.") << qEndl;
63 Status s = mEditor->openObject(inputPath, [](
int){}, [](int){});
66 mErr << qEndl << qEndl << s.title() << qEndl << qEndl;
67 mErr << s.description() << qEndl << qEndl;
68 mErr << s.details().str() << qEndl << qEndl;
75 cameraLayer =
dynamic_cast<LayerCamera*
>(layerManager->findLayerByName(camera, Layer::CAMERA));
76 if (cameraLayer ==
nullptr)
78 mErr <<
tr(
"Warning: the specified camera layer %1 was not found, ignoring.").
arg(camera) << qEndl;
81 if (cameraLayer ==
nullptr)
83 cameraLayer =
dynamic_cast<LayerCamera*
>(layerManager->getLastCameraLayer());
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 Q_ASSERT(!outputPaths.
empty());
104 for (
const QString& outputPath : outputPaths)
107 QString format = detectFormatByFileNameExtension(outputPath);
110 mErr <<
tr(
"Warning: Output format is not specified or unsupported. Using PNG.",
"Command line warning") << qEndl;
114 if (isMovieFormat(format))
116 exportMovie(outputPath, cameraLayer, exportSize, startFrame, endFrame, transparency);
120 exportImageSequence(outputPath, format, cameraLayer, exportSize, startFrame, endFrame, transparency);
126void CommandLineExporter::exportMovie(
const QString &outputPath,
128 const QSize &exportSize,
135 mErr <<
tr(
"Warning: Transparency is not currently supported in movie files",
"Command line warning") << qEndl;
138 mOut <<
tr(
"Exporting movie...",
"Command line task progress") << qEndl;
141 desc.strFileName = outputPath;
142 desc.startFrame = startFrame;
143 desc.endFrame = endFrame;
144 desc.fps = mEditor->playback()->fps();
145 desc.exportSize = exportSize;
146 desc.strCameraName = cameraLayer->name();
149 ex.
run(mEditor->object(), desc, [](
float,
float){}, [](
float){}, [](
const QString &){});
150 mOut <<
tr(
"Done.",
"Command line task done") << qEndl;
153void CommandLineExporter::exportImageSequence(
const QString &outputPath,
156 const QSize &exportSize,
161 mOut <<
tr(
"Exporting image sequence...",
"Command line task progress") << qEndl;
162 mEditor->object()->exportFrames(startFrame,
174 mOut <<
tr(
"Done.",
"Command line task done") << qEndl;
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.
CommandLineExporter(Editor *editor)
Creates a new exporter instance.
int animationLength(bool includeSounds=true)
Get the length of current project.
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.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
bool isNull() const const
QTextStream & endl(QTextStream &stream)