Skip to content

Instantly share code, notes, and snippets.

@dennyabrain
Created February 1, 2026 05:52
Show Gist options
  • Select an option

  • Save dennyabrain/b5e88e2a22bf7740f50859c09942c3c3 to your computer and use it in GitHub Desktop.

Select an option

Save dennyabrain/b5e88e2a22bf7740f50859c09942c3c3 to your computer and use it in GitHub Desktop.
Batch Processsing using FFMPEG in Python
import sys
import subprocess
from pathlib import Path
import os
SOURCE_DIR = Path("../thumbnails")
TARGET_DIR = Path("../thumbnails_avif")
def main():
print("Beginning!")
print(f"Source Directory Exists : {SOURCE_DIR.exists()}")
print(f"Target Directory Exists : {TARGET_DIR.exists()}")
for file in os.listdir(SOURCE_DIR):
print(f"processing : {file}")
file_id = file.split(".")[0]
cmd = f"ffmpeg -i {SOURCE_DIR/file} -c:v libaom-av1 -still-picture 1 {TARGET_DIR/file}"
subprocess.run(cmd, check=True, capture_output=True, text=True, shell=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment