foley.sources.video#
Video inputs of generation (#74): a video’s length, and the audio of a muxed video answer.
A video-to-audio (V2A) backend takes the picture the sound must follow (video=).
How a media input is keyed, recorded, replayed and uploaded (a video and an edit’s
audio= alike) is in foley.sources.media; what only a video needs is here:
video_seconds(): its length, for a backend priced per second of the video (probe=; defaultdefault_probe():ffprobeonPATH, else mixing’sprobe_durationthrough mixing’s ffmpeg resolver;Nonewhen it cannot be read, which prices the call as an unknown cost, needing approval).has_audio_stream(): whether a media file has an audio stream (ffprobe, elsesoundfile;Nonewhen it cannot tell).audio_track(): the audio of a backend’s muxed video answer (MMAudio, ThinkSound and HunyuanVideo-Foley return the video with the sound in it), viaffmpeg(ffmpeg_path()).
The helpers that now serve every media input (#215) were named for the video and are
still importable from here under those names, as plain aliases of their
foley.sources.media versions: video_key() (media_key()),
is_video_key() (is_media_key()),
recorded_video_key() (recorded_media_key()),
video_url() (media_url()),
local_video_file() (local_media_file()) and
VideoInput (MediaValue); the rest of that module’s
names (MEDIA, keyed(), replayable(), RemoteVideo, …) are
re-exported as they are.
Stdlib only (mixing and soundfile are used when installed, never required).
Module Attributes
What |
|
The most |
|
The most |
|
how |
|
whether a media file has an audio stream ( |
Functions
|
The audio of a muxed video, as WAV bytes (16-bit PCM, its own rate and channels). |
|
|
An |
|
|
The length of the video file at |
|
Whether the media file at |
|
The length by mixing's |
|
The length of a local |
- foley.sources.video.AUDIO_TRACK_TIMEOUT_S = 120.0#
The most
audio_track()lets ffmpeg run (s).
- foley.sources.video.AudioStreamCheck#
whether a media file has an audio stream (
None: it cannot tell).has_audio_stream()is the default.- Type:
path -> True | False | None
- foley.sources.video.PROBE_TIMEOUT_S = 30.0#
The most
ffprobe_seconds()lets ffprobe run (s).
- foley.sources.video.Probe#
how
video_seconds()reads a local file’s length.- Type:
video -> seconds | None
- foley.sources.video.VideoInput#
What
video=accepts (MediaValue).alias of
str|RemoteVideo|os.PathLike[str]|bytes
- foley.sources.video.audio_track(container, *, ffmpeg=None, timeout_s=120.0)[source]#
The audio of a muxed video, as WAV bytes (16-bit PCM, its own rate and channels).
Written to a file, not a pipe, so ffmpeg can finish the WAV header (a piped WAV carries a streaming placeholder size).
- Raises:
RuntimeError – If no
ffmpegis found, it cannot read an audio stream, or it runs pasttimeout_s.- Return type:
- foley.sources.video.default_probe(path)[source]#
ffprobe_seconds()(bounded byPROBE_TIMEOUT_S) whenffprobeis onPATH, elsemixing_seconds(). Never both: a file that stalls ffprobe would stall mixing’s unboundedffmpeg -itoo.
- foley.sources.video.ffmpeg_path()[source]#
An
ffmpegbinary: mixing’s resolver (a pip-bundled one too), elsePATH.
- foley.sources.video.ffprobe_seconds(path, *, ffprobe=None)[source]#
The length of the video file at
pathbyffprobe(default: the one onPATH), orNonewhen there is none or it cannot read it.
- foley.sources.video.has_audio_stream(path, *, ffprobe=None)[source]#
Whether the media file at
pathhas an audio stream, orNonewhen that cannot be told.By
ffprobe(default: the one onPATH; bounded byPROBE_TIMEOUT_S):Truewhen it lists an audio stream,Falsewhen it lists none or cannot read the file (a video-only mp4, a gif, an error page),Nonewhen it cannot run or runs too long. Withoutffprobe, bysoundfile(the decoderfoley.audio.load()uses):Truewhen it decodes the file to one or more channels, elseNone(it reads no video container, so its refusal says nothing). A caller that needs an answer treatsNoneas no (fail closed).
- foley.sources.video.mixing_seconds(path)[source]#
The length by mixing’s
probe_duration(ffmpeg -ithrough mixing’s ffmpeg resolver, a pip-bundled ffmpeg too), orNonewhen mixing’s video stack is not installed or finds no ffmpeg. Unbounded: mixing’s probe has no timeout yet (reeleehq/mixing#88).
- foley.sources.video.video_seconds(video, *, probe=None)[source]#
The length of a local
videoin seconds, orNonewhen it cannot be read.probe(path) -> seconds | Nonereads it (default:default_probe()); a probe that raises counts as unreadable. A URL is not fetched to measure it:None.>>> video_seconds(b"...", probe=lambda path: 4.5) 4.5 >>> video_seconds("https://x/clip.mp4", probe=lambda path: 4.5) is None True