Documentation
¶
Overview ¶
Package ffmpeg drives the ffmpeg and ffprobe processes that turn a source into a clip, a GIF, a still, or a preview.
Index ¶
- Constants
- func ChannelLayoutName(channels int) string
- func DefaultFFmpegTimeout() time.Duration
- func DynamicRangeLabel(transfer string) string
- func IsHDRSource(transfer string) bool
- func PreviewDuration(duration time.Duration) time.Duration
- func SourceQuality(info probe.Info) string
- func SourceResolutionLabel(height int) string
- type ExecFFmpeg
- func (execFFmpeg *ExecFFmpeg) DetectCrop(ctx context.Context, input string, start, duration time.Duration) (crop.CropRect, error)
- func (execFFmpeg *ExecFFmpeg) ExtractClip(ctx context.Context, input, output string, start, duration time.Duration, ...) error
- func (execFFmpeg *ExecFFmpeg) ExtractGIF(ctx context.Context, input, output string, start, duration time.Duration, ...) error
- func (execFFmpeg *ExecFFmpeg) ExtractPreview(ctx context.Context, input, output string, start, duration time.Duration, ...) error
- func (execFFmpeg *ExecFFmpeg) ExtractScreenshot(ctx context.Context, input, output string, timestamp time.Duration, ...) error
- func (execFFmpeg *ExecFFmpeg) Probe(ctx context.Context, path string) (probe.Info, error)
Constants ¶
const ( // Height720p is the smallest height still called 720p. Height720p = 720 // Height1080p is the smallest height still called 1080p. Height1080p = 1080 // Height2160p is the smallest height called 4K. Height2160p = 2160 )
Variables ¶
This section is empty.
Functions ¶
func ChannelLayoutName ¶
ChannelLayoutName names common speaker layouts.
Parameters:
- channels: Audio channel count on the source.
Returns:
- name: The layout's display name, or empty when the count is unknown.
func DefaultFFmpegTimeout ¶
DefaultFFmpegTimeout returns the default FFmpeg timeout.
Returns:
- timeout: The per-command deadline.
func DynamicRangeLabel ¶
DynamicRangeLabel names a color transfer for display.
Parameters:
- transfer: ffprobe color_transfer of the source.
Returns:
- label: The transfer's display name, or empty when it is not HDR.
func IsHDRSource ¶
IsHDRSource reports whether a source carries an HDR transfer.
Parameters:
- transfer: ffprobe color_transfer of the source.
Returns:
- hdr: True when the source is PQ or HLG.
func PreviewDuration ¶
PreviewDuration caps a preview window so encodes stay cheap.
Parameters:
- duration: Requested clip duration.
Returns:
- capped: The window that will actually be encoded.
func SourceQuality ¶
SourceQuality is a short label for what a source's video is.
Parameters:
- info: Probed information for the source.
Returns:
- label: The resolution and dynamic range, or empty when neither is known.
func SourceResolutionLabel ¶
SourceResolutionLabel classifies a source height the way a viewer would name it.
Parameters:
- height: Video height in pixels.
Returns:
- label: The class name, or empty when the height is unknown.
Types ¶
type ExecFFmpeg ¶
type ExecFFmpeg struct {
// contains filtered or unexported fields
}
ExecFFmpeg runs the ffmpeg and ffprobe binaries.
func NewExecFFmpeg ¶
func NewExecFFmpeg(ffmpegPath, ffprobePath string) *ExecFFmpeg
NewExecFFmpeg creates a new FFmpeg executor.
Parameters:
- ffmpegPath: Path to the ffmpeg binary.
- ffprobePath: Path to the ffprobe binary.
Returns:
- exec: An executor carrying the default timeout.
func (*ExecFFmpeg) DetectCrop ¶
func (execFFmpeg *ExecFFmpeg) DetectCrop( ctx context.Context, input string, start, duration time.Duration, ) (crop.CropRect, error)
DetectCrop samples the source with cropdetect and returns a crop rectangle.
Parameters:
- ctx: Cancellation and deadline for the pass.
- input: Source media path.
- start: Seek offset into the source.
- duration: Length of the clip.
Returns:
- rect: The detected crop rectangle, or a zero value when there are no bars.
- err: Non-nil only when the pass failed and produced no usable output.
func (*ExecFFmpeg) ExtractClip ¶
func (execFFmpeg *ExecFFmpeg) ExtractClip( ctx context.Context, input, output string, start, duration time.Duration, preset clip.QualityPreset, audioIndex int, rect crop.CropRect, ) error
ExtractClip encodes a clip segment with x264.
Parameters:
- ctx: Cancellation and deadline for the encode.
- input: Source media path.
- output: Destination mp4 path.
- start: Seek offset into the source.
- duration: Length of the clip.
- preset: Encode quality, including WebSafeColor.
- audioIndex: Audio stream index on the source.
- rect: Optional black-bar crop.
Returns:
- err: Non-nil when the clip could not be encoded.
func (*ExecFFmpeg) ExtractGIF ¶
func (execFFmpeg *ExecFFmpeg) ExtractGIF( ctx context.Context, input, output string, start, duration time.Duration, width, fps int, rect crop.CropRect, ) error
ExtractGIF extracts a GIF from a video using the palettegen/paletteuse pair.
Parameters:
- ctx: Cancellation and deadline for both passes.
- input: Source media path.
- output: Destination GIF path.
- start: Seek offset into the source.
- duration: Length of the GIF window.
- width: Output width in pixels, or 0 for the default.
- fps: Output frames per second, or 0 for the default.
- rect: Optional black-bar crop.
Returns:
- err: Non-nil when either pass failed.
func (*ExecFFmpeg) ExtractPreview ¶
func (execFFmpeg *ExecFFmpeg) ExtractPreview( ctx context.Context, input, output string, start, duration time.Duration, audioIndex int, rect crop.CropRect, preset clip.QualityPreset, ) error
ExtractPreview writes a short, downscaled, browser-safe preview segment.
Parameters:
- ctx: Cancellation and deadline for the encode.
- input: Source media path.
- output: Destination mp4 path.
- start: Seek offset into the source.
- duration: Requested window, capped by PreviewDuration.
- audioIndex: Audio stream index on the source.
- rect: Optional black-bar crop.
- preset: Encode options; only WebSafeColor is read.
Returns:
- err: Non-nil when the preview could not be encoded.
func (*ExecFFmpeg) ExtractScreenshot ¶
func (execFFmpeg *ExecFFmpeg) ExtractScreenshot( ctx context.Context, input, output string, timestamp time.Duration, rect crop.CropRect, ) error
ExtractScreenshot extracts a screenshot from a video.
Parameters:
- ctx: Cancellation and deadline for the encode.
- input: Source media path.
- output: Destination image path.
- timestamp: Offset into the source to grab the frame from.
- rect: Optional black-bar crop.
Returns:
- err: Non-nil when the still could not be written.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package crop parses ffmpeg cropdetect rectangles.
|
Package crop parses ffmpeg cropdetect rectangles. |
|
Package probe reads what a source file actually is, using ffprobe.
|
Package probe reads what a source file actually is, using ffprobe. |
|
Package progress reports ffmpeg encode completion from stderr.
|
Package progress reports ffmpeg encode completion from stderr. |
|
Package tonemap builds the ffmpeg filter chain that maps an HDR source down to Rec.709 so a browser renders it the way it was graded.
|
Package tonemap builds the ffmpeg filter chain that maps an HDR source down to Rec.709 so a browser renders it the way it was graded. |