Documentation
¶
Index ¶
- func BurnInSubtitles(inputFile string, opts ...Option) error
- func CompressAudio(inputFile, outputFile string, opts ...Option) error
- func CompressImage(inputFile, outputFile string, opts ...Option) error
- func CompressImageRaw(inputRaw []byte, opts ...Option) ([]byte, error)
- func ExtractImageFramesFromVideo(inputFile string, opts ...Option) (<-chan *FfmpegStreamResult, error)
- func ExtractSpecificFrame(inputFile string, frameNum int) ([]byte, error)
- func GetVideoDuration(inputFile string) (time.Duration, error)
- func StartScreenRecording(outputFile string, opts ...Option) (*exec.Cmd, error)
- type AudioExtractionResult
- type DisplayInfo
- type FfmpegStreamResult
- type Option
- func WithAudioBitrate(bitrate string) Option
- func WithChannels(channels int) Option
- func WithContext(ctx context.Context) Option
- func WithCustomVideoFilter(filter string) Option
- func WithDebug(debug bool) Option
- func WithFontFile(filepath string) Option
- func WithFrameQuality(quality int) Option
- func WithFramesPerSecond(fps float64) Option
- func WithIgnoreBottomPaddingInSceneDetection(enable bool) Option
- func WithOutputAudioFile(filename string) Option
- func WithOutputDir(dir string) Option
- func WithOutputFramePattern(pattern string) Option
- func WithOutputVideoFile(filepath string) Option
- func WithSampleRate(rate int) Option
- func WithSceneThreshold(threshold float64) Option
- func WithScreenCaptureDebug(enable bool) Option
- func WithScreenCaptureMode(mode ScreenCaptureMode) Option
- func WithScreenCaptureQuality(quality ScreenCaptureQuality) Option
- func WithScreenRecordCaptureCursor(capture bool) Option
- func WithScreenRecordFormat(format string) Option
- func WithScreenRecordFramerate(rate int) Option
- func WithScreenRecordInput(input string) Option
- func WithStartEnd(start, end time.Duration) Option
- func WithStartEndSeconds(start, end float64) Option
- func WithSubtitleFile(filepath string) Option
- func WithSubtitlePadding(enable bool) Option
- func WithSubtitleTimestamp(enable bool) Option
- func WithTargetImageSize(sizeInBytes int64) Option
- func WithThreads(n int) Option
- func WithTimestampOverlay(show bool) Option
- type ScreenCaptureMode
- type ScreenCaptureQuality
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BurnInSubtitles ¶
BurnInSubtitles hard-codes subtitles from an SRT file into a video.
func CompressAudio ¶
CompressAudio compresses an audio file to a specified format and bitrate.
func CompressImage ¶
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 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 ¶
ExtractSpecificFrame extracts a single frame at a specific frame number from a video.
func GetVideoDuration ¶
GetVideoDuration extracts the duration of a video file using ffmpeg. It parses the ffmpeg output to find the duration.
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 ¶
WithAudioBitrate sets the target bitrate for audio compression (e.g., "128k").
func WithChannels ¶
WithChannels sets the number of audio channels. Defaults to 1 (mono).
func WithContext ¶
WithContext sets the context for the command.
func WithCustomVideoFilter ¶
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 WithFontFile ¶
WithFontFile specifies the path to a TTF font file for text overlays.
func WithFrameQuality ¶
WithFrameQuality sets the quality for extracted frames (1-31, where 2 is high quality).
func WithFramesPerSecond ¶
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 ¶
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 ¶
WithOutputAudioFile specifies the output file path for the extracted audio. If not set, a temporary file will be created.
func WithOutputDir ¶
WithOutputDir specifies the directory to save extracted frames. If not set, a temporary directory will be created.
func WithOutputFramePattern ¶
WithOutputFramePattern sets the output filename pattern for frames (e.g., "frame-%03d.jpg").
func WithOutputVideoFile ¶
WithOutputVideoFile specifies the path for the final output video.
func WithSampleRate ¶
WithSampleRate sets the audio sample rate. Defaults to 16000.
func WithSceneThreshold ¶
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 ¶
WithScreenCaptureDebug 启用屏幕截图调试信息
func WithScreenCaptureMode ¶
func WithScreenCaptureMode(mode ScreenCaptureMode) Option
WithScreenCaptureMode 设置屏幕截图模式
func WithScreenCaptureQuality ¶
func WithScreenCaptureQuality(quality ScreenCaptureQuality) Option
WithScreenCaptureQuality 设置屏幕截图质量
func WithScreenRecordCaptureCursor ¶
WithScreenRecordCaptureCursor enables or disables capturing the mouse cursor.
func WithScreenRecordFormat ¶
WithScreenRecordFormat sets the input format for screen recording. Common values: "avfoundation" (macOS), "gdigrab" (Windows), "x11grab" (Linux).
func WithScreenRecordFramerate ¶
WithScreenRecordFramerate sets the capture framerate.
func WithScreenRecordInput ¶
WithScreenRecordInput specifies the input source for recording. e.g., "1" (screen), "desktop", "video=Integrated Camera:audio=Built-in Microphone".
func WithStartEnd ¶
WithStartEnd specifies the time range for extraction.
func WithStartEndSeconds ¶
WithStartEndSeconds specifies the time range for extraction in seconds.
func WithSubtitleFile ¶
WithSubtitleFile specifies the path to the SRT subtitle file to burn in.
func WithSubtitlePadding ¶
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 ¶
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 ¶
WithTargetImageSize sets the target file size in bytes for image compression.
func WithThreads ¶
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 ¶
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 // 高质量,无损截图 )