From cd5a090ca5503de8a6701a8034afe29486856632 Mon Sep 17 00:00:00 2001 From: Hannes Date: Sun, 13 Sep 2026 21:16:18 +0200 Subject: [PATCH] first commit --- .gitignore | 2 ++ extract.py | 72 ++++++++++++++++++++++++++++++++++++++++++++ extracted/.gitignore | 0 3 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 extract.py create mode 100644 extracted/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c9dff2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +extracted/*.mp3 +extracted/*.mkv \ No newline at end of file diff --git a/extract.py b/extract.py new file mode 100644 index 0000000..bc3fdb2 --- /dev/null +++ b/extract.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +Extracts the first 1.5 minutes of a video into: + - a video-only file (no audio) + - an audio-only file (no video) +Output goes into an 'extracted' folder next to this script. +Requires: ffmpeg installed and on PATH. +""" + +import subprocess +import os +import sys +import shutil + +# ─── Hardcoded input (relative to this script's directory) ─── +# INPUT_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/honney/Videos/Drachenzähmen/Drachenzaehmen.mp4") +INPUT_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/honney/Videos/Drachenzähmen/How to Train Your Dragon.mkv") +DURATION = 90 # 1.5 minutes in seconds +OUT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "extracted") + +# ─── Check ffmpeg ─── +if shutil.which("ffmpeg") is None: + sys.exit("ERROR: 'ffmpeg' not found on PATH. Install it and try again.") + +# ─── Prepare output folder ─── +os.makedirs(OUT_DIR, exist_ok=True) + +# ─── Derive output filenames ─── +stem = os.path.splitext(os.path.basename(INPUT_FILE))[0] +video_out = os.path.join(OUT_DIR, f"{stem}_video.mkv") +audio_out = os.path.join(OUT_DIR, f"{stem}_audio.mp3") + +print(f"Input : {INPUT_FILE}") +print(f"Video → {video_out}") +print(f"Audio → {audio_out}") +print("-" * 50) + +# ─── Extract video-only (first 90s, no audio) ─── +cmd_video = [ + "ffmpeg", + "-y", # overwrite output + "-i", INPUT_FILE, + "-t", str(DURATION), + "-an", # no audio + "-c:v", "copy", # copy video stream (no re-encode = fast + lossless) + video_out +] +print("[video] running ffmpeg…") +r = subprocess.run(cmd_video, capture_output=True, text=True) +if r.returncode != 0: + sys.exit(f"ffmpeg (video) failed:\n{r.stderr}") +print("[video] done ✔") + +# ─── Extract audio-only (first 90s, no video) ─── +cmd_audio = [ + "ffmpeg", + "-y", + "-i", INPUT_FILE, + "-t", str(DURATION), + "-vn", # no video + "-c:a", "libmp3lame", + "-b:a", "192k", # 192 kbps + audio_out +] +print("[audio] running ffmpeg…") +r = subprocess.run(cmd_audio, capture_output=True, text=True) +if r.returncode != 0: + sys.exit(f"ffmpeg (audio) failed:\n{r.stderr}") +print("[audio] done ✔") + +print("-" * 50) +print("All done. Files are in:", OUT_DIR) diff --git a/extracted/.gitignore b/extracted/.gitignore new file mode 100644 index 0000000..e69de29