Video Modification Simplified
type: NewsArticle
description: The article describes **vid.py**, a Python command-line tool that acts as a simplified wrapper around ffmpeg for common video tasks. It provides functions for parsing timecodes, estimating video duration by probing input files, and rendering a real-time progress bar in the terminal during video processing. The script includes error handling, ffmpeg dependency checking, and verbose output options for user feedback.
date published: 2026-05-21T21:16:56+00:00
date modified: 2026-05-23T21:33:34+00:00
language: en
is accessible for free: true
article body: #!/usr/bin/env python3 """vid — a friendlier CLI wrapper around ffmpeg for common video tasks.""" import argparse import json import os import re import shlex import shutil import subprocess import sys import time from pathlib import Path # Set by main() from --verbose. Read by run() and batch prep commands to # decide whether to print per-file ffmpeg commands and use a per-file bar. _VERBOSE = False def fail(msg): print(f"error: {msg}", file=sys.stderr) sys.exit(1) def check_ffmpeg(): if not shutil.which("ffmpeg"): fail("ffmpeg not found in PATH") def _to_seconds(s): """Parse '30', '1:30', '00:01:30', or '12.5' to a float number of seconds.""" if s is None: return None try: if ":" in s: parts = [float(p) for p in s.split(":")] if len(parts) == 2: return parts[0] * 60 + parts[1] if len(parts) == 3: return parts[0] * 3600 + parts[1] * 60 + parts[2] return float(s) except (ValueError, TypeError): return None def _guess_duration(cmd): """Estimate expected output duration (seconds) from an ffmpeg command.""" # Explicit -t wins for i, arg in enumerate(cmd[:-1]): if arg == "-t": d = _to_seconds(cmd[i + 1]) if d: return d # Otherwise probe the first input and subtract -ss if present. # Prefer the video stream's duration over the container's — DJI MP4s often # have container-level padding past the last video frame, which would make # the progress bar stop short of 100% otherwise. for i, arg in enumerate(cmd[:-1]): if arg == "-i": input_path = cmd[i + 1] if not Path(input_path).is_file(): return None try: data = probe(input_path) v = next((s for s in data["streams"] if s.get("codec_type") == "video"), None) full = None if v and "duration" in v: full = float(v["duration"]) if not full: full = float(data.get("format", {}).get("duration", 0)) if not full: return None except Exception: return None ss = 0.0 for j, a in enumerate(cmd[:i]): if a == "-ss": ss = _to_seconds(cmd[j + 1]) or 0.0 break return max(0.0, full - ss) return None _PROGRESS_TTY = sys.stdout.isatty() def _render…
publisher: Web Pulse
keywords: developer-tools, open-source
mentions: ffmpeg
mentions: Python
citation: CreativeWork