Documentation
¶
Overview ¶
Package media turns command-line arguments into inputs and wraps the local audio tools (ffmpeg, ffprobe, sox).
This file (inputs) belongs to the foundation; tools, trimming, capture, and durations live in the other files of the package.
Index ¶
- func Capture(ctx context.Context, t Tools, seconds int, device string) (outPath string, cleanup func(), err error)
- func Duration(t Tools, path string) (d time.Duration, ok bool)
- func InstallHint(tool string) string
- func IsMediaFile(name string) bool
- func MissingTool(tool, purpose string) *output.Error
- func Trim(ctx context.Context, t Tools, in string, at, dur time.Duration) (outPath string, cleanup func(), err error)
- type Input
- type Tools
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capture ¶
func Capture(ctx context.Context, t Tools, seconds int, device string) (outPath string, cleanup func(), err error)
Capture records seconds of audio from the default input device (or device) into a temporary WAV file, using ffmpeg when installed and sox otherwise. Call cleanup when done with outPath.
Device names by platform (ffmpeg):
macOS avfoundation audio index or name: "0", ":MacBook Pro Microphone"
Linux PulseAudio source ("default", "alsa_input.usb-…"), or ALSA as
"alsa:hw:1,0" / "hw:1,0"; PulseAudio falls back to ALSA
Windows DirectShow device name: "Microphone (USB Audio)"; the first
audio device by default
With sox, device is passed as AUDIODEV.
func Duration ¶
Duration returns the length of a local or remote media file using ffprobe. ok is false when ffprobe is missing or cannot tell.
func InstallHint ¶
InstallHint returns the command that installs tool on this system (ffprobe ships with ffmpeg).
func IsMediaFile ¶
IsMediaFile reports whether name has an audio or video extension.
func MissingTool ¶
MissingTool is the error for a command that needs a tool that is not installed (exit 2, with the install command as the hint).
Types ¶
type Input ¶
type Input struct {
Path string `json:"path,omitempty"`
URL string `json:"url,omitempty"`
IsStdin bool `json:"stdin,omitempty"`
}
Input is one thing to recognize: a local file, a URL, or audio read from stdin (spooled to a temporary file at Path, with IsStdin set).
func ExpandInputs ¶
ExpandInputs resolves recognize-style arguments:
- a URL (http/https) or an existing file: a single input;
- a directory: every audio/video file under it, recursively (hidden files and dirs skipped);
- a glob ("*.mp3", "music/**/*.flac"): matching audio/video files;
- "-": stdin, either a list of files/URLs (one per line, # comments) or audio bytes, which are spooled to a temporary file (call Cleanup);
- several arguments: all of the above, combined.
batch is true for directories, globs, lists, and multiple arguments, even when they resolve to a single file. Duplicate paths are dropped.