All Classes Namespaces Functions Variables Enumerations Properties Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
MovieExporter Class Reference

Public Member Functions

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. More...
 
QString error ()
 
void cancel ()
 

Static Public Member Functions

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. More...
 

Static Public Attributes

static const int MAX_SOUND_FRAMES = 63
 

Private Member Functions

Status assembleAudio (const Object *obj, QString ffmpegPath, std::function< void(float)> progress)
 Combines all audio tracks in obj into a single file. More...
 
Status generateMovie (const Object *obj, QString ffmpegPath, QString strOutputFile, std::function< void(float)> progress)
 Exports obj to a movie image at strOut using FFmpeg. More...
 
Status generateGif (const Object *obj, QString ffmpeg, QString strOut, std::function< void(float)> progress)
 Exports obj to a gif image at strOut using FFmpeg. More...
 
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 time. More...
 
Status checkInputParameters (const ExportMovieDesc &)
 

Private Attributes

QTemporaryDir mTempDir
 
QString mTempWorkDir
 
ExportMovieDesc mDesc
 
bool mCanceled = false
 

Detailed Description

Definition at line 43 of file movieexporter.h.

Member Function Documentation

Status MovieExporter::assembleAudio ( const Object obj,
QString  ffmpegPath,
std::function< void(float)>  progress 
)
private

Combines all audio tracks in obj into a single file.

Parameters
[in]obj
[in]ffmpegPath
[out]progressA function that takes one float argument (the percentage of the audio assembly complete) and may display the output to the user in any way it sees fit.
Returns
Returns the final status of the operation. Ok if successful, or safe if there was intentionally no output.

Definition at line 155 of file movieexporter.cpp.

Status MovieExporter::executeFFmpeg ( const QString cmd,
const QStringList args,
std::function< bool(int)>  progress 
)
static

Runs the specified command (should be ffmpeg) and allows for progress feedback.

Parameters
[in]cmdA string containing the command to execute
[in]argsA string list containing the arguments to pass to the command
[out]progressA function that takes one float argument (the percentage of the ffmpeg operation complete) and may display the output to the user in any way it sees fit.

executeFFMpeg does not allow for writing direct input, the only input through the "-i" argument to specify input files on the disk.

Returns
Returns Status::OK if everything went well, and Status::FAIL and error is detected (usually a non-zero exit code for ffmpeg).

Definition at line 512 of file movieexporter.cpp.

Status MovieExporter::executeFFMpegPipe ( const QString cmd,
const QStringList args,
std::function< void(float)>  progress,
std::function< bool(QProcess &, int)>  writeFrame 
)
private

Runs the specified command (should be ffmpeg), and lets writeFrame pipe data into it 1 frame at a time.

Parameters
[in]cmdA string containing the command to execute
[in]argsA string list containing the arguments to pass to the command
[out]progressA function that takes one float argument (the percentage of the ffmpeg operation complete) and may display the output to the user in any way it sees fit.
[in]writeFrameA function that takes two arguments, a process (the ffmpeg process) and an integer (frames processed or -1, see full description). This function should write a single frame to the process. The function returns true value if it actually wrote a frame.

This function operates generally as follows:

  1. Spawn process with the command from cmd
  2. Check ffmpeg's output for a progress update.
  3. Add frames with writeFrame until it returns false.
  4. Repeat from step 2 until all frames have been written.

The idea is that there are two forms of processing occuring simultaneously, generating frames to send to ffmpeg, and ffmpeg encoding those frames. Whether these this actually occur concurrently or one after another appears to depend on the environment.

The writeFrame function deserves a bit of extra details. It does not only return false when there is an error in generating or writing a frame, it also does it when it wants to "return control" to the rest of the executeFFMpegPipe function for the purposes of reading updates from ffmpeg's output. This should be done every once in a while if possible, but with some formats (specifically gif), all frames must be loaded before any processing can continue, so there is no point returning false for it until all frames have been written. writeFrame is also responsible for closing the writeChannel of the process when it has finished writing all frames. This indicates to executeFFMpegPipe that it no longer needs to call writeFrame.

Returns
Returns Status::OK if everything went well, and Status::FAIL and error is detected (usually a non-zero exit code for ffmpeg).

Definition at line 628 of file movieexporter.cpp.

Status MovieExporter::generateGif ( const Object obj,
QString  ffmpegPath,
QString  strOut,
std::function< void(float)>  progress 
)
private

Exports obj to a gif image at strOut using FFmpeg.

Parameters
[in]objAn Object containing the animation to export.
[in]ffmpegPathThe path to the FFmpeg binary.
[in]strOutThe output path. Should end with .gif.
[out]progressA function that takes one float argument (the percentage of the gif generation complete) and may display the output to the user in any way it sees fit.
Returns
Returns the final status of the operation (ok or canceled)

Definition at line 396 of file movieexporter.cpp.

Status MovieExporter::generateMovie ( const Object obj,
QString  ffmpegPath,
QString  strOutputFile,
std::function< void(float)>  progress 
)
private

Exports obj to a movie image at strOut using FFmpeg.

Parameters
[in]objAn Object containing the animation to export.
[in]ffmpegPathThe path to the FFmpeg binary.
[in]strOutputFileThe output path. Should end with .gif.
[out]progressA function that takes one float argument (the percentage of the gif generation complete) and may display the output to the user in any way it sees fit.

The movie formats supported by this operation are any file formats that the referenced FFmpeg binary supports and that have the required features (ex. video and audio support)

Returns
Returns the final status of the operation (ok or canceled)

Definition at line 251 of file movieexporter.cpp.

Status MovieExporter::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.

Parameters
[in]objAn Object containing the animation to export.
[in]descA structure containing all the export parameters. See ExportMovieDesc.
[out]majorProgressA function to update the major progress bar. The major progress bar goes from 0-100% only one time, representing the overall progress of the export. The first float parameter is the current progress %, and the second is the desired progress when the next sub-task completes. This should only be called at the beginning of a subtask.
[out]minorProgressA function to update the minor progress bar. The minor progress bar goes from 0-100% for each sub-task of the exporting process. It is up to minor progress to update the major progress bar to reflect the sub-task progress.
[out]progressMessageA function ot update the progres bar message. The messages will describe the current sub-task of the exporting process.
Returns
Returns Status:OK on success, or Status::FAIL on error.

Definition at line 71 of file movieexporter.cpp.


The documentation for this class was generated from the following files: