Documentation
¶
Overview ¶
Package transcode 提供 FFmpeg 转码引擎集成
本包实现了基于 FFmpeg 的视频转码功能:
- 支持多种输入/输出格式
- 支持硬件加速编解码
- 支持滤镜处理
- 支持实时流转码
Index ¶
- Variables
- func Transcode(ctx context.Context, input, output string, config Config) error
- func TranscodeReader(ctx context.Context, input io.Reader, output io.Writer, config Config) error
- type AudioConfig
- type Config
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) Open(inputURL string) error
- func (e *Engine) Progress() Progress
- func (e *Engine) SetCompleteCallback(fn func())
- func (e *Engine) SetErrorCallback(fn func(error))
- func (e *Engine) SetOutput(outputURL string, format string) error
- func (e *Engine) SetProgressCallback(fn func(Progress))
- func (e *Engine) Start(ctx context.Context) error
- func (e *Engine) State() EngineState
- func (e *Engine) Stop() error
- func (e *Engine) Wait() error
- type EngineState
- type Progress
- type VideoConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotInitialized = errors.New("transcode: engine not initialized") ErrAlreadyRunning = errors.New("transcode: engine already running") ErrInvalidInput = errors.New("transcode: invalid input") ErrInvalidOutput = errors.New("transcode: invalid output") ErrEncodeFailed = errors.New("transcode: encode failed") ErrDecodeFailed = errors.New("transcode: decode failed") )
错误定义
Functions ¶
func Transcode ¶
Transcode 便捷函数:转码文件
Types ¶
type AudioConfig ¶
type AudioConfig struct {
Codec av.CodecType // 目标编码格式
SampleRate int // 采样率
Channels int // 声道数
Bitrate int // 码率 (bps)
}
AudioConfig 音频转码配置
type Config ¶
type Config struct {
Video *VideoConfig // 视频配置(nil 表示复制)
Audio *AudioConfig // 音频配置(nil 表示复制)
CopyVideo bool // 直接复制视频流
CopyAudio bool // 直接复制音频流
StartTime time.Duration // 开始时间
Duration time.Duration // 持续时间(0 表示到结尾)
Threads int // 编码线程数
HWDevice string // 硬件设备类型
HWDeviceID string // 硬件设备 ID
}
Config 转码配置
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine FFmpeg 转码引擎
func (*Engine) SetCompleteCallback ¶
func (e *Engine) SetCompleteCallback(fn func())
SetCompleteCallback 设置完成回调
func (*Engine) SetErrorCallback ¶
SetErrorCallback 设置错误回调
func (*Engine) SetOutput ¶
SetOutput 设置输出
func (*Engine) SetProgressCallback ¶
SetProgressCallback 设置进度回调
type EngineState ¶
type EngineState int32
EngineState 转码引擎状态
const ( StateIdle EngineState = iota StateRunning StatePaused StateStopping StateStopped StateFailed )
type Progress ¶
type Progress struct {
FramesIn int64 // 输入帧数
FramesOut int64 // 输出帧数
BytesIn int64 // 输入字节数
BytesOut int64 // 输出字节数
Duration time.Duration // 已处理时长
Elapsed time.Duration // 已运行时间
Speed float64 // 处理速度(相对于实时)
BitrateIn float64 // 输入码率 (kbps)
BitrateOut float64 // 输出码率 (kbps)
PercentDone float64 // 完成百分比
EstimatedTime time.Duration // 预计剩余时间
}
Progress 转码进度
type VideoConfig ¶
type VideoConfig struct {
Codec av.CodecType // 目标编码格式
Width int // 目标宽度(0 表示保持原始)
Height int // 目标高度(0 表示保持原始)
Bitrate int // 目标码率 (bps)
FPS int // 目标帧率(0 表示保持原始)
Profile string // 编码 profile
Preset string // 编码预设
CRF int // 恒定质量因子(0 表示使用码率模式)
GOPSize int // GOP 大小
BFrames int // B 帧数量
PixelFmt string // 像素格式
Filters string // FFmpeg 滤镜字符串
Hardware bool // 启用硬件加速
}
VideoConfig 视频转码配置
Source Files
¶
- engine.go
Click to show internal directories.
Click to hide internal directories.