pub struct VideoEncoder { /* private fields */ }Expand description
Video encoder.
Encodes video frames to a file using FFmpeg.
§Examples
use ff_encode::{VideoEncoder, VideoCodec};
use ff_format::VideoFrame;
let mut encoder = VideoEncoder::create("output.mp4")
.expect("Failed to create encoder")
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264)
.build()
.expect("Failed to build encoder");
// Push frames
let frames = vec![]; // Your video frames here
for frame in frames {
encoder.push_video(&frame).expect("Failed to push frame");
}
encoder.finish().expect("Failed to finish encoding");Implementations§
Source§impl VideoEncoder
impl VideoEncoder
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<EncoderBuilder, EncodeError>
pub fn create<P: AsRef<Path>>(path: P) -> Result<EncoderBuilder, EncodeError>
Create a new encoder builder with the given output path.
§Arguments
path- Output file path
§Returns
Returns an EncoderBuilder for configuring the encoder.
§Examples
use ff_encode::VideoEncoder;
let builder = VideoEncoder::create("output.mp4")?;Sourcepub fn actual_video_codec(&self) -> &str
pub fn actual_video_codec(&self) -> &str
Get the actual video codec being used.
Returns the name of the FFmpeg encoder (e.g., “h264_nvenc”, “libx264”).
Sourcepub fn actual_audio_codec(&self) -> &str
pub fn actual_audio_codec(&self) -> &str
Get the actual audio codec being used.
Returns the name of the FFmpeg encoder (e.g., “aac”, “libopus”).
Sourcepub fn hardware_encoder(&self) -> HardwareEncoder
pub fn hardware_encoder(&self) -> HardwareEncoder
Get the hardware encoder actually being used.
Returns the hardware encoder type that is actually being used for encoding. This may differ from what was requested if the requested encoder is not available.
§Examples
use ff_encode::{VideoEncoder, VideoCodec, HardwareEncoder};
let encoder = VideoEncoder::create("output.mp4")?
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264)
.hardware_encoder(HardwareEncoder::Auto)
.build()?;
println!("Using hardware encoder: {:?}", encoder.hardware_encoder());Sourcepub fn is_hardware_encoding(&self) -> bool
pub fn is_hardware_encoding(&self) -> bool
Check if hardware encoding is being used.
Returns true if the encoder is using hardware acceleration,
false if using software encoding.
§Examples
use ff_encode::{VideoEncoder, VideoCodec, HardwareEncoder};
let encoder = VideoEncoder::create("output.mp4")?
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264)
.hardware_encoder(HardwareEncoder::Auto)
.build()?;
if encoder.is_hardware_encoding() {
println!("Using hardware encoder: {}", encoder.actual_video_codec());
} else {
println!("Using software encoder: {}", encoder.actual_video_codec());
}Sourcepub fn is_lgpl_compliant(&self) -> bool
pub fn is_lgpl_compliant(&self) -> bool
Check if the actually selected video encoder is LGPL-compliant.
Returns true if the encoder is safe for commercial use without licensing fees.
Returns false for GPL encoders that require licensing.
§LGPL-Compatible Encoders (Commercial Use OK)
- Hardware encoders: h264_nvenc, h264_qsv, h264_amf, h264_videotoolbox, h264_vaapi
- Royalty-free codecs: libvpx-vp9, libaom-av1, libsvtav1
- Professional codecs: prores_ks, dnxhd
§GPL Encoders (Licensing Required)
- libx264: Requires MPEG LA H.264 license for commercial distribution
- libx265: Requires MPEG LA H.265 license for commercial distribution
§Examples
use ff_encode::{VideoEncoder, VideoCodec, HardwareEncoder};
// Default: Will use hardware encoder or VP9 fallback (LGPL-compliant)
let encoder = VideoEncoder::create("output.mp4")?
.video(1920, 1080, 30.0)
.video_codec(VideoCodec::H264)
.build()?;
if encoder.is_lgpl_compliant() {
println!("✓ Safe for commercial use: {}", encoder.actual_video_codec());
} else {
println!("⚠ GPL encoder (requires licensing): {}", encoder.actual_video_codec());
}§Note
By default (without gpl feature), this will always return true because
the encoder automatically selects LGPL-compatible alternatives.
Sourcepub fn push_video(&mut self, frame: &VideoFrame) -> Result<(), EncodeError>
pub fn push_video(&mut self, frame: &VideoFrame) -> Result<(), EncodeError>
Sourcepub fn push_audio(&mut self, frame: &AudioFrame) -> Result<(), EncodeError>
pub fn push_audio(&mut self, frame: &AudioFrame) -> Result<(), EncodeError>
Push an audio frame for encoding.
§Arguments
frame- The audio frame to encode
§Errors
Returns an error if encoding fails or the encoder is not initialized.
Returns EncodeError::Cancelled if the progress callback requested cancellation.
§Examples
use ff_encode::{VideoEncoder, AudioCodec};
use ff_format::AudioFrame;
let mut encoder = VideoEncoder::create("output.mp4")?
.video(1920, 1080, 30.0)
.audio(48000, 2)
.audio_codec(AudioCodec::Aac)
.build()?;
// Push audio frames
let frame = AudioFrame::empty(1024, 2, 48000, ff_format::SampleFormat::F32)?;
encoder.push_audio(&frame)?;