pub struct VideoEncoderBuilder { /* private fields */ }Expand description
Builder for constructing a VideoEncoder.
Created by calling VideoEncoder::create(). Call build()
to open the output file and prepare for encoding.
§Examples
use ff_encode::{VideoEncoder, VideoCodec, Preset};
let mut encoder = VideoEncoder::create("output.mp4")
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264)
.preset(Preset::Medium)
.build()?;Implementations§
Source§impl VideoEncoderBuilder
impl VideoEncoderBuilder
Sourcepub fn video_codec(self, codec: VideoCodec) -> Self
pub fn video_codec(self, codec: VideoCodec) -> Self
Set video codec.
Sourcepub fn bitrate_mode(self, mode: BitrateMode) -> Self
pub fn bitrate_mode(self, mode: BitrateMode) -> Self
Set the bitrate control mode for video encoding.
Sourcepub fn hardware_encoder(self, hw: HardwareEncoder) -> Self
pub fn hardware_encoder(self, hw: HardwareEncoder) -> Self
Set hardware encoder.
Sourcepub fn audio_codec(self, codec: AudioCodec) -> Self
pub fn audio_codec(self, codec: AudioCodec) -> Self
Set audio codec.
Sourcepub fn audio_bitrate(self, bitrate: u64) -> Self
pub fn audio_bitrate(self, bitrate: u64) -> Self
Set audio bitrate in bits per second.
Sourcepub fn container(self, container: Container) -> Self
pub fn container(self, container: Container) -> Self
Set container format explicitly (usually auto-detected from file extension).
Sourcepub fn on_progress<F>(self, callback: F) -> Self
pub fn on_progress<F>(self, callback: F) -> Self
Set a closure as the progress callback.
Sourcepub fn progress_callback<C: ProgressCallback + 'static>(
self,
callback: C,
) -> Self
pub fn progress_callback<C: ProgressCallback + 'static>( self, callback: C, ) -> Self
Set a ProgressCallback trait object (supports cancellation).
Sourcepub fn two_pass(self) -> Self
pub fn two_pass(self) -> Self
Enable two-pass encoding for more accurate bitrate distribution.
Two-pass encoding is video-only and is incompatible with audio streams.
Sourcepub fn metadata(self, key: &str, value: &str) -> Self
pub fn metadata(self, key: &str, value: &str) -> Self
Embed a metadata tag in the output container.
Calls av_dict_set on AVFormatContext->metadata before the header
is written. Multiple calls accumulate entries; duplicate keys use the
last value.
Sourcepub fn chapter(self, chapter: ChapterInfo) -> Self
pub fn chapter(self, chapter: ChapterInfo) -> Self
Add a chapter to the output container.
Allocates an AVChapter entry on AVFormatContext before the header
is written. Multiple calls accumulate chapters in the order added.
Sourcepub fn subtitle_passthrough(
self,
source_path: &str,
stream_index: usize,
) -> Self
pub fn subtitle_passthrough( self, source_path: &str, stream_index: usize, ) -> Self
Copy a subtitle stream from an existing file into the output container.
Opens source_path, locates the stream at stream_index, and registers it
as a passthrough stream in the output. Packets are copied verbatim using
av_interleaved_write_frame without re-encoding.
stream_index is the zero-based index of the subtitle stream inside
source_path. For files with a single subtitle track this is typically 0
(or whichever index ffprobe reports).
If the source cannot be opened or the stream index is invalid, a warning is logged and encoding continues without subtitles.
Sourcepub fn build(self) -> Result<VideoEncoder, EncodeError>
pub fn build(self) -> Result<VideoEncoder, EncodeError>
Validate builder state and open the output file.
§Errors
Returns EncodeError if configuration is invalid, the output path
cannot be created, or no suitable encoder is found.