mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-03-23 11:26:45 +08:00
refactor: 重构 ffmpeg 编码器探测模块
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
//! This module provides video encoding capabilities including:
|
||||
//! - JPEG encoding for raw frames (YUYV, NV12, etc.)
|
||||
//! - H264 encoding (hardware + software)
|
||||
//! - H265 encoding (hardware only)
|
||||
//! - VP8 encoding (hardware only - VAAPI)
|
||||
//! - VP9 encoding (hardware only - VAAPI)
|
||||
//! - H265 encoding (hardware + software)
|
||||
//! - VP8 encoding (hardware + software)
|
||||
//! - VP9 encoding (hardware + software)
|
||||
//! - WebRTC video codec abstraction
|
||||
//! - Encoder registry for automatic detection
|
||||
|
||||
use hwcodec::common::DataFormat;
|
||||
use hwcodec::ffmpeg_ram::CodecInfo;
|
||||
|
||||
pub mod codec;
|
||||
pub mod h264;
|
||||
pub mod h265;
|
||||
@@ -32,14 +35,45 @@ pub use registry::{AvailableEncoder, EncoderBackend, EncoderRegistry, VideoEncod
|
||||
// H264 encoder
|
||||
pub use h264::{H264Config, H264Encoder, H264EncoderType, H264InputFormat};
|
||||
|
||||
// H265 encoder (hardware only)
|
||||
// H265 encoder
|
||||
pub use h265::{H265Config, H265Encoder, H265EncoderType, H265InputFormat};
|
||||
|
||||
// VP8 encoder (hardware only)
|
||||
// VP8 encoder
|
||||
pub use vp8::{VP8Config, VP8Encoder, VP8EncoderType, VP8InputFormat};
|
||||
|
||||
// VP9 encoder (hardware only)
|
||||
// VP9 encoder
|
||||
pub use vp9::{VP9Config, VP9Encoder, VP9EncoderType, VP9InputFormat};
|
||||
|
||||
// JPEG encoder
|
||||
pub use jpeg::JpegEncoder;
|
||||
|
||||
pub(crate) fn select_codec_for_format<F>(
|
||||
encoders: &[CodecInfo],
|
||||
format: DataFormat,
|
||||
preferred: F,
|
||||
) -> Option<&CodecInfo>
|
||||
where
|
||||
F: Fn(&CodecInfo) -> bool,
|
||||
{
|
||||
encoders
|
||||
.iter()
|
||||
.find(|codec| codec.format == format && preferred(codec))
|
||||
.or_else(|| encoders.iter().find(|codec| codec.format == format))
|
||||
}
|
||||
|
||||
pub(crate) fn detect_best_codec_for_format<T, F>(
|
||||
encoders: &[CodecInfo],
|
||||
format: DataFormat,
|
||||
preferred: F,
|
||||
) -> Option<(T, String)>
|
||||
where
|
||||
T: From<EncoderBackend>,
|
||||
F: Fn(&CodecInfo) -> bool,
|
||||
{
|
||||
select_codec_for_format(encoders, format, preferred).map(|codec| {
|
||||
(
|
||||
T::from(EncoderBackend::from_codec_name(&codec.name)),
|
||||
codec.name.clone(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user