All Classes Namespaces Functions Variables Enumerations Properties Pages
movieexporter.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2012-2020 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 
17 #ifndef MOVIEEXPORTER_H
18 #define MOVIEEXPORTER_H
19 
20 #include <functional>
21 #include <QCoreApplication>
22 #include <QString>
23 #include <QSize>
24 #include <QTemporaryDir>
25 #include "pencilerror.h"
26 
27 class Object;
28 class QProcess;
29 
31 {
32  QString strFileName;
33  int startFrame = 0;
34  int endFrame = 0;
35  //int videoFps = 30;
36  int fps = 12;
37  QSize exportSize{ 0, 0 };
38  QString strCameraName;
39  bool loop = false;
40  bool alpha = false;
41 };
42 
44 {
45  Q_DECLARE_TR_FUNCTIONS(MovieExporter)
46 public:
47  MovieExporter();
48  ~MovieExporter();
49 
50  Status run(const Object* obj,
51  const ExportMovieDesc& desc,
52  std::function<void(float, float)> majorProgress,
53  std::function<void(float)> minorProgress,
54  std::function<void(QString)> progressMessage);
55  QString error();
56 
57  void cancel() { mCanceled = true; }
58 
59  // The maximum number of sound frames that can be successfully rendered
60  static const int MAX_SOUND_FRAMES = 63;
61 
62  static Status executeFFmpeg(const QString& cmd, const QStringList& args, std::function<bool(int)> progress);
63 private:
64  Status assembleAudio(const Object* obj, QString ffmpegPath, std::function<void(float)> progress);
65  Status generateMovie(const Object *obj, QString ffmpegPath, QString strOutputFile, std::function<void(float)> progress);
66  Status generateGif(const Object *obj, QString ffmpeg, QString strOut, std::function<void(float)> progress);
67 
68  Status executeFFMpegPipe(const QString& cmd, const QStringList& args, std::function<void(float)> progress, std::function<bool(QProcess&,int)> writeFrame);
69  Status checkInputParameters(const ExportMovieDesc&);
70 
71 private:
72  QTemporaryDir mTempDir;
73  QString mTempWorkDir;
74  ExportMovieDesc mDesc;
75  bool mCanceled = false;
76 };
77 
78 #endif // MOVIEEXPORTER_H
Status assembleAudio(const Object *obj, QString ffmpegPath, std::function< void(float)> progress)
Combines all audio tracks in obj into a single file.
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.
static Status executeFFmpeg(const QString &cmd, const QStringList &args, std::function< bool(int)> progress)
Runs the specified command (should be ffmpeg) and allows for progress feedback.
Definition: object.h:41
Status generateGif(const Object *obj, QString ffmpeg, QString strOut, std::function< void(float)> progress)
Exports obj to a gif image at strOut using FFmpeg.
Status generateMovie(const Object *obj, QString ffmpegPath, QString strOutputFile, std::function< void(float)> progress)
Exports obj to a movie image at strOut using FFmpeg.
Status executeFFMpegPipe(const QString &cmd, const QStringList &args, std::function< void(float)> progress, std::function< bool(QProcess &, int)> writeFrame)
Runs the specified command (should be ffmpeg), and lets writeFrame pipe data into it 1 frame at a tim...