Skip to content

Commit 0a063b8

Browse files
committed
FFmpegWriter: Overload Set___Options() methods
Add overloaded forms of SetVideoOptions() and SetAudioOptions() that apply some sensible defaults to rarely-changed parameters.
1 parent 49972b2 commit 0a063b8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/FFmpegWriter.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ namespace openshot {
287287
/// @param bit_rate The audio bit rate used during encoding
288288
void SetAudioOptions(bool has_audio, std::string codec, int sample_rate, int channels, openshot::ChannelLayout channel_layout, int bit_rate);
289289

290+
/// @brief Set audio export options.
291+
///
292+
/// Enables the stream and configures a default 2-channel stereo layout.
293+
///
294+
/// @param codec The codec used to encode the audio for this file
295+
/// @param sample_rate The number of audio samples needed in this file
296+
/// @param bit_rate The audio bit rate used during encoding
297+
void SetAudioOptions(std::string codec, int sample_rate, int bit_rate);
298+
290299
/// @brief Set the cache size
291300
/// @param new_size The number of frames to queue before writing to the file
292301
void SetCacheSize(int new_size) { cache_size = new_size; };
@@ -303,8 +312,20 @@ namespace openshot {
303312
/// @param bit_rate The video bit rate used during encoding
304313
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);
305314

315+
/// @brief Set video export options.
316+
///
317+
/// Enables the stream and configures non-interlaced video with a 1:1 pixel aspect ratio.
318+
///
319+
/// @param codec The codec used to encode the images in this video
320+
/// @param fps The number of frames per second
321+
/// @param width The width in pixels of this video
322+
/// @param height The height in pixels of this video
323+
/// @param bit_rate The video bit rate used during encoding
324+
void SetVideoOptions(std::string codec, openshot::Fraction fps, int width, int height, int bit_rate);
325+
306326
/// @brief Set custom options (some codecs accept additional params). This must be called after the
307327
/// PrepareStreams() method, otherwise the streams have not been initialized yet.
328+
///
308329
/// @param stream The stream (openshot::StreamType) this option should apply to
309330
/// @param name The name of the option you want to set (i.e. qmin, qmax, etc...)
310331
/// @param value The new value of this option

src/FFmpegWriter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ void FFmpegWriter::SetVideoOptions(bool has_video, std::string codec, Fraction f
277277
info.has_video = has_video;
278278
}
279279

280+
// Set video export options (overloaded function)
281+
void FFmpegWriter::SetVideoOptions(std::string codec, Fraction fps, int width, int height, int bit_rate) {
282+
// Call full signature with some default parameters
283+
FFmpegWriter::SetVideoOptions(true, codec, fps, width, height,
284+
openshot::Fraction(1, 1), false, true, bit_rate);
285+
}
286+
287+
280288
// Set audio export options
281289
void FFmpegWriter::SetAudioOptions(bool has_audio, std::string codec, int sample_rate, int channels, ChannelLayout channel_layout, int bit_rate) {
282290
// Set audio options
@@ -312,6 +320,14 @@ void FFmpegWriter::SetAudioOptions(bool has_audio, std::string codec, int sample
312320
info.has_audio = has_audio;
313321
}
314322

323+
324+
// Set audio export options (overloaded function)
325+
void FFmpegWriter::SetAudioOptions(std::string codec, int sample_rate, int bit_rate) {
326+
// Call full signature with some default parameters
327+
FFmpegWriter::SetAudioOptions(true, codec, sample_rate, 2, openshot::LAYOUT_STEREO, bit_rate);
328+
}
329+
330+
315331
// Set custom options (some codecs accept additional params)
316332
void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string value) {
317333
// Declare codec context

0 commit comments

Comments
 (0)