Python: captionbob.video
captionbob.video.video_probe
The facts of a video file, read with ffprobe.
The facts are those of the first video stream, because the filter graph of the burn reads the first video stream. A phone video is often kept on its side with a rotation, and ffmpeg turns its frames upright before the filters. So the frame size of a video with a quarter turn is the size of the upright frame. The frame rate is the average frame rate of the stream.
Source file: captionbob/video/video_probe.py
ProbedVideo
@dataclass(frozen=True)
class ProbedVideo
The facts of one video file.
Args:
info: The frame size as it is shown, the frame rate and the duration.has_audio: True when the file has a sound stream.
probe_command
def probe_command(ffprobe_path: Path, video_path: Path) -> list[str]
Give the ffprobe command that reads the facts of a video as JSON.
Args:
ffprobe_path: The ffprobe of the environment.video_path: The video file.
Returns:
The command and its arguments.
frame_rate_from_text
def frame_rate_from_text(text: Any) -> Fraction
Give the frame rate of a text such as 25/1 or 30000/1001.
Args:
text: The frame rate as two whole numbers with / between them.
Returns:
The frame rate as an exact fraction.
Raises:
ValueError: When the text is not a fraction above 0.
video_from_probe
def video_from_probe(record: Any) -> ProbedVideo
Read the facts of a video from the JSON that ffprobe gave.
Args:
record: The JSON object of probe_command.
Returns:
The facts of the first video stream and whether there is sound.
Raises:
ValueError: When there is no video stream, or when a fact is missing or impossible.
probe_video
def probe_video(ffprobe_path: Path, video_path: Path) -> ProbedVideo
Read the facts of a video file with ffprobe.
Args:
ffprobe_path: The ffprobe of the environment.video_path: The video file.
Returns:
The facts of the video.
Raises:
FileNotFoundError: When the ffprobe or the video is not a file.RuntimeError: When ffprobe fails.ValueError: When the result has no video stream or an impossible fact.