filter

package
v0.0.0-...-ae8f3be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package filter 提供基于 FFmpeg 的视频滤镜处理功能。

本包整合了滤镜图执行和滤镜表达式构建功能,提供:

  • 滤镜图创建和执行
  • 滤镜表达式构建器
  • 常用滤镜(缩放、旋转、去隔行、水印等)

基本用法:

// 使用滤镜执行器
runner := filter.NewRunner("scale=1920:1080", 30)
defer runner.Close()
outFrame, err := runner.Process(inFrame)

// 使用滤镜构建器
expr := filter.NewBuilder().
    Scale(1920, 1080).
    Rotate(90).
    Build()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyExpr

func ApplyExpr(expr string, frame *astiav.Frame, fps int) (*astiav.Frame, error)

ApplyExpr 应用滤镜表达式到单个帧(便捷函数)

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder 滤镜表达式构建器

func NewBuilder

func NewBuilder() *Builder

NewBuilder 创建滤镜构建器

func (*Builder) Build

func (b *Builder) Build() string

Build 构建滤镜表达式

func (*Builder) Custom

func (b *Builder) Custom(expr string) *Builder

Custom 添加自定义滤镜表达式

func (*Builder) Deinterlace

func (b *Builder) Deinterlace(method DeinterlaceMethod) *Builder

Deinterlace 添加去隔行滤镜

func (*Builder) Format

func (b *Builder) Format(pixelFormat string) *Builder

Format 添加像素格式转换滤镜

func (*Builder) ImageWatermark

func (b *Builder) ImageWatermark(opts ImageWatermarkOptions) *Builder

ImageWatermark 添加图片水印滤镜(返回完整的滤镜图表达式)

func (*Builder) Reset

func (b *Builder) Reset() *Builder

Reset 重置构建器

func (*Builder) Rotate

func (b *Builder) Rotate(degrees int) *Builder

Rotate 添加旋转滤镜

func (*Builder) Scale

func (b *Builder) Scale(width, height int) *Builder

Scale 添加缩放滤镜

func (*Builder) TextWatermark

func (b *Builder) TextWatermark(opts TextWatermarkOptions) *Builder

TextWatermark 添加文字水印滤镜

func (*Builder) Tonemap

func (b *Builder) Tonemap(opts TonemapOptions) *Builder

Tonemap 添加色调映射滤镜(HDR 转 SDR)

type DeinterlaceMethod

type DeinterlaceMethod string

DeinterlaceMethod 去隔行方法

const (
	DeinterlaceYadif DeinterlaceMethod = "yadif"
	DeinterlaceBwdif DeinterlaceMethod = "bwdif"
	DeinterlaceBob   DeinterlaceMethod = "bob"
	DeinterlaceWeave DeinterlaceMethod = "weave"
	DeinterlaceBlend DeinterlaceMethod = "blend"
)

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph 滤镜图

func NewGraph

func NewGraph(expr string, frame *astiav.Frame, fps int) (*Graph, error)

NewGraph 创建滤镜图

func (*Graph) Free

func (f *Graph) Free()

Free 释放滤镜图资源

type ImageWatermarkOptions

type ImageWatermarkOptions struct {
	ImagePath string
	Position  WatermarkPosition
	Opacity   float64
	Scale     float64
	OffsetX   int
	OffsetY   int
}

ImageWatermarkOptions 图片水印选项

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner 滤镜执行器

func NewRunner

func NewRunner(expr string, fps int) *Runner

NewRunner 创建滤镜执行器

func (*Runner) Close

func (r *Runner) Close()

Close 关闭滤镜执行器并释放资源

func (*Runner) Flush

func (r *Runner) Flush() error

Flush 刷新滤镜缓冲区

func (*Runner) Process

func (r *Runner) Process(frame *astiav.Frame) (*astiav.Frame, error)

Process 处理单个视频帧

func (*Runner) ProcessFrames

func (r *Runner) ProcessFrames(frame *astiav.Frame) ([]*astiav.Frame, error)

ProcessFrames 处理视频帧并返回所有输出帧

type TextWatermarkOptions

type TextWatermarkOptions struct {
	Text      string
	FontFile  string
	FontSize  int
	FontColor string
	Position  WatermarkPosition
	Opacity   float64
	OffsetX   int
	OffsetY   int
}

TextWatermarkOptions 文字水印选项

type TonemapAlgorithm

type TonemapAlgorithm string

TonemapAlgorithm 色调映射算法

const (
	TonemapBT2390   TonemapAlgorithm = "bt2390"
	TonemapHable    TonemapAlgorithm = "hable"
	TonemapMobius   TonemapAlgorithm = "mobius"
	TonemapReinhard TonemapAlgorithm = "reinhard"
)

type TonemapOptions

type TonemapOptions struct {
	Algorithm TonemapAlgorithm
	Mode      string // "auto", "rgb", "yuv"
	Range     string // "auto", "tv", "pc"
	Desat     float64
	Peak      float64
}

TonemapOptions 色调映射选项

type WatermarkPosition

type WatermarkPosition string

WatermarkPosition 水印位置

const (
	WatermarkTopLeft     WatermarkPosition = "top_left"
	WatermarkTopRight    WatermarkPosition = "top_right"
	WatermarkBottomLeft  WatermarkPosition = "bottom_left"
	WatermarkBottomRight WatermarkPosition = "bottom_right"
	WatermarkCenter      WatermarkPosition = "center"
)

Source Files

  • builder.go
  • doc.go
  • graph.go
  • runner.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL