Skip to content

Commit

Permalink
FFmpegWriter: Overload Set___Options() methods
Browse files Browse the repository at this point in the history
Add overloaded forms of SetVideoOptions() and SetAudioOptions()
that apply some sensible defaults to rarely-changed parameters.
  • Loading branch information
ferdnyc committed Jan 31, 2020
1 parent 49972b2 commit 0a063b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/FFmpegWriter.h
Expand Up @@ -287,6 +287,15 @@ namespace openshot {
/// @param bit_rate The audio bit rate used during encoding
void SetAudioOptions(bool has_audio, std::string codec, int sample_rate, int channels, openshot::ChannelLayout channel_layout, int bit_rate);

/// @brief Set audio export options.
///
/// Enables the stream and configures a default 2-channel stereo layout.
///
/// @param codec The codec used to encode the audio for this file
/// @param sample_rate The number of audio samples needed in this file
/// @param bit_rate The audio bit rate used during encoding
void SetAudioOptions(std::string codec, int sample_rate, int bit_rate);

/// @brief Set the cache size
/// @param new_size The number of frames to queue before writing to the file
void SetCacheSize(int new_size) { cache_size = new_size; };
Expand All @@ -303,8 +312,20 @@ namespace openshot {
/// @param bit_rate The video bit rate used during encoding
void SetVideoOptions(bool has_video, std::string codec, openshot::Fraction fps, int width, int height, openshot::Fraction pixel_ratio, bool interlaced, bool top_field_first, int bit_rate);

/// @brief Set video export options.
///
/// Enables the stream and configures non-interlaced video with a 1:1 pixel aspect ratio.
///
/// @param codec The codec used to encode the images in this video
/// @param fps The number of frames per second
/// @param width The width in pixels of this video
/// @param height The height in pixels of this video
/// @param bit_rate The video bit rate used during encoding
void SetVideoOptions(std::string codec, openshot::Fraction fps, int width, int height, int bit_rate);

/// @brief Set custom options (some codecs accept additional params). This must be called after the
/// PrepareStreams() method, otherwise the streams have not been initialized yet.
///
/// @param stream The stream (openshot::StreamType) this option should apply to
/// @param name The name of the option you want to set (i.e. qmin, qmax, etc...)
/// @param value The new value of this option
Expand Down
16 changes: 16 additions & 0 deletions src/FFmpegWriter.cpp
Expand Up @@ -277,6 +277,14 @@ void FFmpegWriter::SetVideoOptions(bool has_video, std::string codec, Fraction f
info.has_video = has_video;
}

// Set video export options (overloaded function)
void FFmpegWriter::SetVideoOptions(std::string codec, Fraction fps, int width, int height, int bit_rate) {
// Call full signature with some default parameters
FFmpegWriter::SetVideoOptions(true, codec, fps, width, height,
openshot::Fraction(1, 1), false, true, bit_rate);
}


// Set audio export options
void FFmpegWriter::SetAudioOptions(bool has_audio, std::string codec, int sample_rate, int channels, ChannelLayout channel_layout, int bit_rate) {
// Set audio options
Expand Down Expand Up @@ -312,6 +320,14 @@ void FFmpegWriter::SetAudioOptions(bool has_audio, std::string codec, int sample
info.has_audio = has_audio;
}


// Set audio export options (overloaded function)
void FFmpegWriter::SetAudioOptions(std::string codec, int sample_rate, int bit_rate) {
// Call full signature with some default parameters
FFmpegWriter::SetAudioOptions(true, codec, sample_rate, 2, openshot::LAYOUT_STEREO, bit_rate);
}


// Set custom options (some codecs accept additional params)
void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string value) {
// Declare codec context
Expand Down

0 comments on commit 0a063b8

Please sign in to comment.