ffmpegutils

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BurnInSubtitles

func BurnInSubtitles(inputFile string, opts ...Option) error

BurnInSubtitles hard-codes subtitles from an SRT file into a video.

func CompressAudio

func CompressAudio(inputFile, outputFile string, opts ...Option) error

CompressAudio compresses an audio file to a specified format and bitrate.

func CompressImage

func CompressImage(inputFile, outputFile string, opts ...Option) error

CompressImage resizes an image to be under a target size, saving it to outputFile. It iteratively adjusts the JPEG quality to meet the size constraint.

func CompressImageRaw

func CompressImageRaw(inputRaw []byte, opts ...Option) ([]byte, error)

func ExtractImageFramesFromVideo

func ExtractImageFramesFromVideo(inputFile string, opts ...Option) (<-chan *FfmpegStreamResult, error)

ExtractImageFramesFromVideo extracts frames from a video and streams the results. It returns a channel that provides FfmpegStreamResult for each frame created.

func ExtractSpecificFrame

func ExtractSpecificFrame(inputFile string, frameNum int) ([]byte, error)

ExtractSpecificFrame extracts a single frame at a specific frame number from a video.

func GetVideoDuration

func GetVideoDuration(inputFile string) (time.Duration, error)

GetVideoDuration extracts the duration of a video file using ffmpeg. It parses the ffmpeg output to find the duration.

func StartScreenRecording

func StartScreenRecording(outputFile string, opts ...Option) (*exec.Cmd, error)

StartScreenRecording starts a non-blocking ffmpeg process for screen recording. It returns the command instance, allowing the caller to manage its lifecycle (e.g., wait or kill).

Types

type AudioExtractionResult

type AudioExtractionResult struct {
	// FilePath is the path to the extracted audio file.
	FilePath string
	// Duration is the duration of the extracted audio.
	Duration time.Duration
}

AudioExtractionResult holds the results of an audio extraction operation.

func ExtractAudioFromVideo

func ExtractAudioFromVideo(inputFile string, opts ...Option) (*AudioExtractionResult, error)

ExtractAudioFromVideo extracts audio from a video file and saves it as a new audio file.

type DisplayInfo

type DisplayInfo struct {
	ID      int    // 显示器ID
	X       int    // X偏移
	Y       int    // Y偏移
	Width   int    // 宽度
	Height  int    // 高度
	Name    string // 显示器名称
	Primary bool   // 是否为主显示器
}

DisplayInfo 表示显示器信息

type FfmpegStreamResult

type FfmpegStreamResult struct {
	// MIMEType is the detected MIME type of the raw data.
	MIMEType    string
	MIMETypeObj *mimetype.MIME
	// RawData is the raw byte content of the result.
	RawData []byte
	// Timestamp is the exact time of the frame in the video.
	Timestamp time.Duration
	// Error captures any issue that occurred while processing this specific result.
	Error error
}

FfmpegStreamResult holds the result of a single data unit from a stream, typically an image frame.

func ExtractUserScreenShot

func ExtractUserScreenShot(opts ...Option) (*FfmpegStreamResult, error)

ExtractUserScreenShot 捕获用户屏幕截图,支持多屏幕处理

func (*FfmpegStreamResult) SaveToFile

func (f *FfmpegStreamResult) SaveToFile() (string, error)

type Option

type Option func(*options)

Option defines the functional option type.

func WithAudioBitrate

func WithAudioBitrate(bitrate string) Option

WithAudioBitrate sets the target bitrate for audio compression (e.g., "128k").

func WithChannels

func WithChannels(channels int) Option

WithChannels sets the number of audio channels. Defaults to 1 (mono).

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the command.

func WithCustomVideoFilter

func WithCustomVideoFilter(filter string) Option

WithCustomVideoFilter provides a way to specify a custom -vf filter string. This will OVERRIDE any filter settings from WithSceneThreshold or WithFramesPerSecond. Use with caution.

func WithDebug

func WithDebug(debug bool) Option

WithDebug enables verbose logging for the ffmpeg command.

func WithFontFile

func WithFontFile(filepath string) Option

WithFontFile specifies the path to a TTF font file for text overlays.

func WithFrameQuality

func WithFrameQuality(quality int) Option

WithFrameQuality sets the quality for extracted frames (1-31, where 2 is high quality).

func WithFramesPerSecond

func WithFramesPerSecond(fps float64) Option

WithFramesPerSecond sets a fixed rate for frame extraction. Using this option sets the extraction mode to fixed rate. It is mutually exclusive with WithSceneThreshold.

func WithIgnoreBottomPaddingInSceneDetection

func WithIgnoreBottomPaddingInSceneDetection(enable bool) Option

WithIgnoreBottomPaddingInSceneDetection controls whether scene detection should ignore the bottom padding area. When enabled, scene detection will only analyze the original video content, ignoring changes in timestamp/subtitle areas. This is particularly useful when extracting frames with timestamps or subtitles to avoid false scene changes.

func WithOutputAudioFile

func WithOutputAudioFile(filename string) Option

WithOutputAudioFile specifies the output file path for the extracted audio. If not set, a temporary file will be created.

func WithOutputDir

func WithOutputDir(dir string) Option

WithOutputDir specifies the directory to save extracted frames. If not set, a temporary directory will be created.

func WithOutputFramePattern

func WithOutputFramePattern(pattern string) Option

WithOutputFramePattern sets the output filename pattern for frames (e.g., "frame-%03d.jpg").

func WithOutputVideoFile

func WithOutputVideoFile(filepath string) Option

WithOutputVideoFile specifies the path for the final output video.

func WithSampleRate

func WithSampleRate(rate int) Option

WithSampleRate sets the audio sample rate. Defaults to 16000.

func WithSceneThreshold

func WithSceneThreshold(threshold float64) Option

WithSceneThreshold sets the scene change detection sensitivity (0.0 to 1.0). Using this option sets the extraction mode to scene change detection. It is mutually exclusive with WithFramesPerSecond.

func WithScreenCaptureDebug

func WithScreenCaptureDebug(enable bool) Option

WithScreenCaptureDebug 启用屏幕截图调试信息

func WithScreenCaptureMode

func WithScreenCaptureMode(mode ScreenCaptureMode) Option

WithScreenCaptureMode 设置屏幕截图模式

func WithScreenCaptureQuality

func WithScreenCaptureQuality(quality ScreenCaptureQuality) Option

WithScreenCaptureQuality 设置屏幕截图质量

func WithScreenRecordCaptureCursor

func WithScreenRecordCaptureCursor(capture bool) Option

WithScreenRecordCaptureCursor enables or disables capturing the mouse cursor.

func WithScreenRecordFormat

func WithScreenRecordFormat(format string) Option

WithScreenRecordFormat sets the input format for screen recording. Common values: "avfoundation" (macOS), "gdigrab" (Windows), "x11grab" (Linux).

func WithScreenRecordFramerate

func WithScreenRecordFramerate(rate int) Option

WithScreenRecordFramerate sets the capture framerate.

func WithScreenRecordInput

func WithScreenRecordInput(input string) Option

WithScreenRecordInput specifies the input source for recording. e.g., "1" (screen), "desktop", "video=Integrated Camera:audio=Built-in Microphone".

func WithStartEnd

func WithStartEnd(start, end time.Duration) Option

WithStartEnd specifies the time range for extraction.

func WithStartEndSeconds

func WithStartEndSeconds(start, end float64) Option

WithStartEndSeconds specifies the time range for extraction in seconds.

func WithSubtitleFile

func WithSubtitleFile(filepath string) Option

WithSubtitleFile specifies the path to the SRT subtitle file to burn in.

func WithSubtitlePadding

func WithSubtitlePadding(enable bool) Option

WithSubtitlePadding enables or disables adding black padding for subtitles. When enabled, black padding will be added to the bottom of the video where subtitles are displayed, ensuring subtitles don't cover the original video content.

func WithSubtitleTimestamp

func WithSubtitleTimestamp(enable bool) Option

WithSubtitleTimestamp sets whether to show timestamp information within subtitle text. When enabled, each subtitle line will include timing information like "(start: 00:01:23 ---> end: 00:01:26)".

func WithTargetImageSize

func WithTargetImageSize(sizeInBytes int64) Option

WithTargetImageSize sets the target file size in bytes for image compression.

func WithThreads

func WithThreads(n int) Option

WithThreads sets the number of threads for ffmpeg to use. A value of 0 (the default) allows ffmpeg to choose the best value.

func WithTimestampOverlay

func WithTimestampOverlay(show bool) Option

WithTimestampOverlay enables or disables timestamp overlay on extracted frames. When enabled, a black bar will be added at the bottom of each frame displaying the timestamp.

type ScreenCaptureMode

type ScreenCaptureMode int

ScreenCaptureMode 定义屏幕截图模式

const (
	CaptureSingle   ScreenCaptureMode = iota // 捕获单个屏幕
	CaptureAll                               // 捕获所有屏幕并拼接
	CaptureMultiple                          // 捕获多个屏幕作为单独文件
)

type ScreenCaptureQuality

type ScreenCaptureQuality int

ScreenCaptureQuality 定义屏幕截图质量级别

const (
	QualityLow    ScreenCaptureQuality = iota // 低质量,快速截图
	QualityNormal                             // 正常质量
	QualityHigh                               // 高质量,无损截图
)

Jump to

Keyboard shortcuts

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