Files
mytoolkit/bin/commands/video.py
T
Zhengshou Lai c1df4098b3 refactor: rename package from mytoolkit to bin
- Move all source files from mytoolkit/ to bin/
- Update entry point and build config in pyproject.toml
- Add pillow and pypdf dependencies
- Update README and .gitignore paths
- Remove unused subprocess import in pdf.py
- Clean up duplicate imports in pdf merge command
2026-04-26 09:56:29 +08:00

38 lines
1009 B
Python

"""Video utilities."""
import subprocess
from pathlib import Path
import click
from bin.utils import handle_errors, run_command
@click.group()
def video():
"""Video conversion commands."""
pass
@video.command("avi-to-mp4")
@click.argument("files", nargs=-1, required=True)
@click.option("--dry-run", "-n", is_flag=True, help="Show what would be done")
@handle_errors
def avi_to_mp4(files, dry_run):
"""Convert AVI files to MP4 using ffmpeg."""
for pattern in files:
for avi_file in Path(".").glob(pattern):
if avi_file.suffix.lower() != ".avi":
continue
output = avi_file.with_suffix(".mp4")
if dry_run:
click.echo(f"Would convert: {avi_file} -> {output}")
continue
click.echo(f"Converting: {avi_file} -> {output}")
run_command(
["ffmpeg", "-i", str(avi_file), "-c:v", "libx264", "-c:a", "aac", str(output)],
check=False,
)