OpenShot Library | libopenshot
0.1.9
|
This class uses the FFmpeg libraries, to write and encode video files and audio files. More...
#include <FFmpegWriter.h>
Public Member Functions | |
void | Close () |
Close the writer. More... | |
FFmpegWriter (string path) | |
Constructor for FFmpegWriter. Throws one of the following exceptions. More... | |
int | GetCacheSize () |
Get the cache size (number of frames to queue before writing) More... | |
bool | IsOpen () |
Determine if writer is open or closed. More... | |
void | Open () |
Open writer. More... | |
void | OutputStreamInfo () |
Output the ffmpeg info about this format, streams, and codecs (i.e. dump format) More... | |
void | PrepareStreams () |
Prepare & initialize streams and open codecs. This method is called automatically by the Open() method if this method has not yet been called. More... | |
void | RemoveScalers () |
Remove & deallocate all software scalers. More... | |
void | ResampleAudio (int sample_rate, int channels) |
Set audio resample options. More... | |
void | SetAudioOptions (bool has_audio, string codec, int sample_rate, int channels, ChannelLayout channel_layout, int bit_rate) |
Set audio export options. More... | |
void | SetCacheSize (int new_size) |
Set the cache size. More... | |
void | SetOption (StreamType stream, string name, string value) |
Set custom options (some codecs accept additional params). This must be called after the PrepareStreams() method, otherwise the streams have not been initialized yet. More... | |
void | SetVideoOptions (bool has_video, string codec, Fraction fps, int width, int height, Fraction pixel_ratio, bool interlaced, bool top_field_first, int bit_rate) |
Set 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... | |
void | WriteHeader () |
Write the file header (after the options are set). This method is called automatically by the Open() method if this method has not yet been called. More... | |
void | WriteTrailer () |
Write the file trailer (after all frames are written). This is called automatically by the Close() method if this method has not yet been called. More... | |
![]() | |
void | CopyReaderInfo (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... | |
string | Json () |
Get and Set JSON methods. More... | |
Json::Value | JsonValue () |
Generate Json::JsonValue for this object. More... | |
void | SetJson (string value) |
Load JSON string into this object. More... | |
void | SetJsonValue (Json::Value root) |
Load Json::JsonValue into this object. More... | |
WriterBase () | |
Constructor for WriterBase class, many things are initialized here. More... | |
Additional Inherited Members | |
![]() | |
WriterInfo | info |
Information about the current media file. More... | |
This class uses the FFmpeg libraries, to write and encode video files and audio files.
All FFmpeg options can be set using the SetOption() method, and any Reader may be used to generate openshot::Frame objects needed for writing. Be sure to use valid bit rates, frame rates, and sample rates (each format / codec has a limited # of valid options).
Here is a more advanced example, which sets some additional (and optional) encoding options.
Definition at line 143 of file FFmpegWriter.h.
FFmpegWriter::FFmpegWriter | ( | string | path | ) |
Constructor for FFmpegWriter. Throws one of the following exceptions.
path | The file path of the video file you want to open and read |
Definition at line 35 of file FFmpegWriter.cpp.
void FFmpegWriter::Close | ( | ) |
Close the writer.
Definition at line 721 of file FFmpegWriter.cpp.
|
inline |
Get the cache size (number of frames to queue before writing)
Definition at line 256 of file FFmpegWriter.h.
|
inlinevirtual |
Determine if writer is open or closed.
Implements openshot::WriterBase.
Definition at line 259 of file FFmpegWriter.h.
|
virtual |
void FFmpegWriter::OutputStreamInfo | ( | ) |
Output the ffmpeg info about this format, streams, and codecs (i.e. dump format)
Definition at line 1587 of file FFmpegWriter.cpp.
void FFmpegWriter::PrepareStreams | ( | ) |
Prepare & initialize streams and open codecs. This method is called automatically by the Open() method if this method has not yet been called.
Definition at line 301 of file FFmpegWriter.cpp.
void FFmpegWriter::RemoveScalers | ( | ) |
Remove & deallocate all software scalers.
Definition at line 1618 of file FFmpegWriter.cpp.
void FFmpegWriter::ResampleAudio | ( | int | sample_rate, |
int | channels | ||
) |
Set audio resample options.
sample_rate | The number of samples per second of the audio |
channels | The number of audio channels |
Definition at line 1612 of file FFmpegWriter.cpp.
void FFmpegWriter::SetAudioOptions | ( | bool | has_audio, |
string | codec, | ||
int | sample_rate, | ||
int | channels, | ||
ChannelLayout | channel_layout, | ||
int | bit_rate | ||
) |
Set audio export options.
has_audio | Does this file need an audio stream? |
codec | The codec used to encode the audio for this file |
sample_rate | The number of audio samples needed in this file |
channels | The number of audio channels needed in this file |
channel_layout | The 'layout' of audio channels (i.e. mono, stereo, surround, etc...) |
bit_rate | The audio bit rate used during encoding |
Definition at line 172 of file FFmpegWriter.cpp.
|
inline |
Set the cache size.
new_size | The number of frames to queue before writing to the file |
Definition at line 290 of file FFmpegWriter.h.
void FFmpegWriter::SetOption | ( | StreamType | stream, |
string | name, | ||
string | value | ||
) |
Set custom options (some codecs accept additional params). This must be called after the PrepareStreams() method, otherwise the streams have not been initialized yet.
stream | The stream (openshot::StreamType) this option should apply to |
name | The name of the option you want to set (i.e. qmin, qmax, etc...) |
value | The new value of this option |
Definition at line 210 of file FFmpegWriter.cpp.
void FFmpegWriter::SetVideoOptions | ( | bool | has_video, |
string | codec, | ||
Fraction | fps, | ||
int | width, | ||
int | height, | ||
Fraction | pixel_ratio, | ||
bool | interlaced, | ||
bool | top_field_first, | ||
int | bit_rate | ||
) |
Set video export options.
has_video | Does this file need a video stream |
codec | The codec used to encode the images in this video |
fps | The number of frames per second |
width | The width in pixels of this video |
height | The height in pixels of this video |
pixel_ratio | The shape of the pixels represented as a openshot::Fraction (1x1 is most common / square pixels) |
interlaced | Does this video need to be interlaced? |
top_field_first | Which frame should be used as the top field? |
bit_rate | The video bit rate used during encoding |
Definition at line 114 of file FFmpegWriter.cpp.
|
virtual |
Add a frame to the stack waiting to be encoded.
frame | The openshot::Frame object to write to this image |
Implements openshot::WriterBase.
Definition at line 347 of file FFmpegWriter.cpp.
|
virtual |
Write a block of frames from a reader.
reader | A openshot::ReaderBase object which will provide frames to be written |
start | The starting frame number of the reader |
length | The number of frames to write |
Implements openshot::WriterBase.
Definition at line 501 of file FFmpegWriter.cpp.
void FFmpegWriter::WriteHeader | ( | ) |
Write the file header (after the options are set). This method is called automatically by the Open() method if this method has not yet been called.
Definition at line 322 of file FFmpegWriter.cpp.
void FFmpegWriter::WriteTrailer | ( | ) |
Write the file trailer (after all frames are written). This is called automatically by the Close() method if this method has not yet been called.
Definition at line 517 of file FFmpegWriter.cpp.