← back to AgentAbrams
media/video.py
65 lines
#!/usr/bin/env python3
"""
media/video.py — Create video from audio + static cover image.
For full avatar+screen layout, use video/compose_video.sh instead.
Usage:
python3 media/video.py <audio.mp3> [output.mp4]
"""
import subprocess
import sys
from pathlib import Path
def build_video(audio_file: str, output_file: str = "media/output/video.mp4"):
Path(output_file).parent.mkdir(parents=True, exist_ok=True)
cover = "assets/cover.png"
if not Path(cover).exists():
Path("assets").mkdir(parents=True, exist_ok=True)
subprocess.run(
[
"ffmpeg", "-y",
"-f", "lavfi",
"-i", "color=c=0x1a1a2e:s=1920x1080:d=1",
"-vframes", "1",
cover,
],
check=True,
)
print(f"Generated placeholder cover: {cover}")
subprocess.run(
[
"ffmpeg", "-y",
"-loop", "1",
"-i", cover,
"-i", audio_file,
"-c:v", "libx264",
"-tune", "stillimage",
"-preset", "fast",
"-crf", "23",
"-c:a", "aac",
"-b:a", "192k",
"-shortest",
output_file,
],
check=True,
)
print(f"Video created: {output_file}")
def main():
if len(sys.argv) < 2:
print("Usage: video.py <audio.mp3> [output.mp4]", file=sys.stderr)
sys.exit(2)
output = sys.argv[2] if len(sys.argv) > 2 else "media/output/video.mp4"
build_video(sys.argv[1], output)
if __name__ == "__main__":
main()