38 lines
1011 B
Python
38 lines
1011 B
Python
"""Video utilities."""
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import click
|
|
|
|
from mycli.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,
|
|
)
|