Skip to content

Instantly share code, notes, and snippets.

@iver56
Created June 5, 2024 06:38
Show Gist options
  • Save iver56/e4f7a278213548ecf113191de155bc8b to your computer and use it in GitHub Desktop.
Save iver56/e4f7a278213548ecf113191de155bc8b to your computer and use it in GitHub Desktop.
import subprocess
from pathlib import Path
input_video_path = r"C:\Users\Iver\Videos\my_video.mkv"
clips = [
{"start": "16:10", "end": "20:08", "name": "Good vibrations"},
{"start": "21:08", "end": "23:10", "name": "Mister Sandman"},
{"start": "24:20", "end": "27:10", "name": "Ave Verum"},
{"start": "28:04", "end": "29:59", "name": "White Winter Hymnal"},
]
output_dir = r"C:\Users\Iver\Videos\clips"
for clip in clips:
command = [
"ffmpeg",
"-y",
"-i",
Path(input_video_path).as_posix(),
"-c:v",
"copy",
"-c:a",
"flac",
"-ss",
clip["start"],
"-to",
clip["end"],
(Path(output_dir) / f"{clip['name']}.mp4").as_posix(),
]
# Run the command and display the output in the console
subprocess.run(command, check=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment