OpenShot Library | libopenshot  0.2.5
Public Member Functions | List of all members
openshot::ImageWriter Class Reference

This class uses the ImageMagick library to write image files (including animated GIFs) More...

#include <ImageWriter.h>

Inheritance diagram for openshot::ImageWriter:
openshot::WriterBase

Public Member Functions

void Close ()
 Close the writer and encode/output final image to the disk. This is a requirement of ImageMagick, which writes all frames of a multi-frame image at one time. More...
 
int GetCacheSize ()
 Get the cache size. More...
 
 ImageWriter (std::string path)
 Constructor for ImageWriter. Throws one of the following exceptions. More...
 
bool IsOpen ()
 Determine if writer is open or closed. More...
 
void Open ()
 Open writer. More...
 
void SetCacheSize (int new_size)
 Set the cache size (number of frames to queue before writing) More...
 
void SetVideoOptions (std::string format, Fraction fps, int width, int height, int quality, int loops, bool combine)
 Set the video export options. More...
 
void WriteFrame (std::shared_ptr< Frame > frame)
 Add a frame to the stack waiting to be encoded. More...
 
void WriteFrame (ReaderBase *reader, int64_t start, int64_t length)
 Write a block of frames from a reader. More...
 
- Public Member Functions inherited from openshot::WriterBase
void CopyReaderInfo (openshot::ReaderBase *reader)
 This method copy's the info struct of a reader, and sets the writer with the same info. More...
 
void DisplayInfo ()
 Display file information in the standard output stream (stdout) More...
 
std::string Json () const
 Get and Set JSON methods. More...
 
Json::Value JsonValue () const
 Generate Json::Value for this object. More...
 
void SetJson (const std::string value)
 Load JSON string into this object. More...
 
void SetJsonValue (const Json::Value root)
 Load Json::Value into this object. More...
 
virtual void WriteFrame (std::shared_ptr< openshot::Frame > frame)=0
 This method is required for all derived classes of WriterBase. Write a Frame to the video file. More...
 
 WriterBase ()
 Constructor for WriterBase class, many things are initialized here. More...
 
virtual ~WriterBase ()=default
 

Additional Inherited Members

- Public Attributes inherited from openshot::WriterBase
WriterInfo info
 Information about the current media file. More...
 

Detailed Description

This class uses the ImageMagick library to write image files (including animated GIFs)

All image formats supported by ImageMagick are supported by this class.

// Create a reader for a video
FFmpegReader r("MyAwesomeVideo.webm");
r.Open(); // Open the reader
// Create a writer (which will create an animated GIF file)
ImageWriter w("/home/jonathan/NewAnimation.gif");
// Set the image output settings (format, fps, width, height, quality, loops, combine)
w.SetVideoOptions("GIF", r.info.fps, r.info.width, r.info.height, 70, 1, true);
// Open the writer
w.Open();
// Write the 1st 30 frames from the reader
w.WriteFrame(&r, 1, 30);
// Close the reader & writer
w.Close();
r.Close();

Definition at line 86 of file ImageWriter.h.

Constructor & Destructor Documentation

◆ ImageWriter()

ImageWriter::ImageWriter ( std::string  path)

Constructor for ImageWriter. Throws one of the following exceptions.

Parameters
pathThe path of the file you want to create

Definition at line 41 of file ImageWriter.cpp.

Member Function Documentation

◆ Close()

void ImageWriter::Close ( )

Close the writer and encode/output final image to the disk. This is a requirement of ImageMagick, which writes all frames of a multi-frame image at one time.

Definition at line 145 of file ImageWriter.cpp.

◆ GetCacheSize()

int openshot::ImageWriter::GetCacheSize ( )
inline

Get the cache size.

Definition at line 111 of file ImageWriter.h.

◆ IsOpen()

bool openshot::ImageWriter::IsOpen ( )
inlinevirtual

Determine if writer is open or closed.

Implements openshot::WriterBase.

Definition at line 114 of file ImageWriter.h.

◆ Open()

void ImageWriter::Open ( )
virtual

Open writer.

Implements openshot::WriterBase.

Definition at line 89 of file ImageWriter.cpp.

Referenced by IsOpen().

◆ SetCacheSize()

void openshot::ImageWriter::SetCacheSize ( int  new_size)
inline

Set the cache size (number of frames to queue before writing)

Parameters
new_sizeNumber of frames to queue before writing

Definition at line 121 of file ImageWriter.h.

◆ SetVideoOptions()

void ImageWriter::SetVideoOptions ( std::string  format,
Fraction  fps,
int  width,
int  height,
int  quality,
int  loops,
bool  combine 
)

Set the video export options.

Parameters
formatThe image format (such as GIF)
fpsFrames per second of the image (used on certain multi-frame image formats, such as GIF)
widthWidth in pixels of image
heightHeight in pixels of image
qualityQuality of image (0 to 100, 70 is default)
loopsNumber of times to repeat the image (used on certain multi-frame image formats, such as GIF)
combineCombine frames into a single image (if possible), or save each frame as its own image

Definition at line 51 of file ImageWriter.cpp.

Referenced by SetCacheSize().

◆ WriteFrame() [1/2]

void ImageWriter::WriteFrame ( std::shared_ptr< Frame frame)

Add a frame to the stack waiting to be encoded.

Parameters
frameThe openshot::Frame object to write to this image

Definition at line 95 of file ImageWriter.cpp.

Referenced by SetCacheSize(), and WriteFrame().

◆ WriteFrame() [2/2]

void ImageWriter::WriteFrame ( ReaderBase reader,
int64_t  start,
int64_t  length 
)
virtual

Write a block of frames from a reader.

Parameters
readerA openshot::ReaderBase object which will provide frames to be written
startThe starting frame number of the reader
lengthThe number of frames to write

Implements openshot::WriterBase.

Definition at line 129 of file ImageWriter.cpp.


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