Monday, September 14, 2026

The Repurposing Machine: How an Automated Pipeline Slices Long-Form Video for the TikTok Era

 The Repurposing Machine: How an Automated Pipeline Slices Long-Form Video for the TikTok Era

SAN FRANCISCO — In the modern creator economy, long-form content faces a brutal mathematical reality: without an aggressive presence on vertical feeds like TikTok, Instagram Reels, and YouTube Shorts, even high-production documentary work risks obscurity. Yet the process of manually isolating narrative highlights, cropping horizontal aspect ratios, and transcribing subtitles word-for-word remains one of digital media’s most tedious bottlenecks.

A specialized Python automation tool dubbed Auto-Clipper & AI Subtitle Generator provides an answer. Built entirely with open-source tools, it bridges yt-dlp, FFmpeg, and OpenAI’s Whisper to turn a full-length YouTube documentary into a suite of ready-to-publish vertical clips with synchronized subtitles in a single pass.

The Architecture: Five Logical Stages

Rather than relying on closed web editors that require monthly subscriptions and cloud queueing, this utility executes entirely on local hardware through a clean five-stage pipeline.

1.Source Acquisition :yt-dlp high-resolution stream extraction.

The script accepts any target YouTube URL and inspects the local directory. If the master file (troie_complet.mp4) does not already exist, yt-dlp pulls the highest-quality video and audio streams, muxing them directly into a persistent MP4 container.

2.Temporal Slicing & Timeline Coordinates :

Users define narrative hooks as a list of segment tuples—each holding a unique slug, start timestamp, and end timestamp (e.g., ("1_Cassandre", "00:02:03", "00:03:00")).

3.Dual-Layer 9:16 Aspect Conversion :FFmpeg boxblur complex filtergraph.

Instead of aggressively cropping out the sides of 16:9 shots—which cuts off subjects and action—the engine builds a layered vertical canvas (1080x1920). It splits the stream into two: a scaled, blurred background (boxblur=20:10) that fills the vertical frame, and a proportional foreground video centered on top.

4.Local Speech-to-Text Transcription :OpenAI Whisper neural acoustic processing.

The local Whisper model (small) ingests each extracted vertical MP4, running offline transformer inference to decipher dialogue, segment speech boundaries, and calculate millisecond-level timestamps without API fees.

5.SRT Timestamp Formatting & Export :

Raw transcription segments are parsed by a mathematical converter (secondes_vers_srt_time) that formats seconds into standard subtitle timecodes (HH:MM:SS,mmm). It outputs a companion .srt file matched to each clip.

The Complete Production Script (app.py)

Here is the cleaned and structured implementation, ready to run:

Python
import os
import subprocess
import yt_dlp
import whisper

# 1. Environment & Target Definition
dossier_clipper = r"C:\Users\YourUser\Desktop\CLIPPER"
os.makedirs(dossier_clipper, exist_ok=True)
os.chdir(dossier_clipper)

url = "https://www.youtube.com/watch?v=T7iVwJb0BfE"
video_mere = "troie_complet.mp4"

# 2. Ingest Master Video
if not os.path.exists(video_mere):
    print("📥 Downloading original video stream...")
    ydl_opts = {
        'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]',
        'outtmpl': video_mere,
    }
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])

# 3. Define Clip Manifest (Slug, In-Point, Out-Point)
clips = [
    ("1_Cassandre", "00:02:03", "00:03:00"),
    ("2_Pomme_d_or", "00:05:17", "00:07:30"),
    ("3_Sacrifice_Iphigenie", "00:15:14", "00:16:30"),
    ("5_Cheval_de_Troie", "00:28:53", "00:31:30")
]

# 4. Vertical Canvas Generation (FFmpeg)
for nom, debut, fin in clips:
    fichier_vertical = f"{nom}_916.mp4"
    if not os.path.exists(fichier_vertical):
        print(f"\n🎬 Rendering vertical clip: {nom}...")
        
        # Split: Blurred full-bleed background + Centered proportional foreground
        filter_916 = (
            "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=20:10[bg];"
            "[0:v]scale=1080:1920:force_original_aspect_ratio=decrease[fg];"
            "[bg][fg]overlay=(W-w)/2:(H-h)/2"
        )
        
        cmd = [
            "ffmpeg", "-y",
            "-ss", debut, "-to", fin,
            "-i", video_mere,
            "-filter_complex", filter_916,
            "-c:v", "libx264", "-crf", "23",
            "-c:a", "copy",
            fichier_vertical
        ]
        subprocess.run(cmd, check=True)

# 5. Offline Neural Transcription & Subtitle Assembly
print("\n🧠 Loading OpenAI Whisper model...")
model = whisper.load_model("small")

def secondes_vers_srt_time(secondes):
    heures = int(secondes // 3600)
    minutes = int((secondes % 3600) // 60)
    secs = int(secondes % 60)
    mils = int((secondes - int(secondes)) * 1000)
    return f"{heures:02d}:{minutes:02d}:{secs:02d},{mils:03d}"

for nom, _, _ in clips:
    fichier_video = f"{nom}_916.mp4"
    fichier_srt = f"{nom}_916.srt"
    
    if os.path.exists(fichier_video) and not os.path.exists(fichier_srt):
        print(f"✍️ Generating subtitle track for {fichier_video}...")
        result = model.transcribe(fichier_video, language="en")
        
        with open(fichier_srt, "w", encoding="utf-8") as srt_file:
            for idx, segment in enumerate(result["segments"], start=1):
                start = secondes_vers_srt_time(segment["start"])
                end = secondes_vers_srt_time(segment["end"])
                text = segment["text"].strip()
                srt_file.write(f"{idx}\n{start} --> {end}\n{text}\n\n")
                
        print(f" Subtitle ready: {fichier_srt}")

print("\n Automation run completed. Video and subtitle assets generated.")

Output File System

Once executed, the output workspace is neatly organized for immediate publishing or import into Premiere Pro, DaVinci Resolve, or CapCut:

Plaintext
CLIPPER/
├── troie_complet.mp4             # Master reference capture
├── 1_Cassandre_916.mp4           # 1080x1920 Short clip
├── 1_Cassandre_916.srt           # Synchronized captions
├── 2_Pomme_d_or_916.mp4
├── 2_Pomme_d_or_916.srt
├── 3_Sacrifice_Iphigenie_916.mp4
├── 3_Sacrifice_Iphigenie_916.srt
├── 5_Cheval_de_Troie_916.mp4
└── 5_Cheval_de_Troie_916.srt

The Broader Shift

By treating video editing not as a manual timeline task but as a data-transformation script, this pipeline highlights how independent creators can match the posting velocity of entire production teams. The combination of lightweight command-line media engines and efficient local speech models strips out hours of manual labor, turning long-form archival content into viral vertical media automatically.

No comments:

Post a Comment

Generated Code to the Test Across Two Continents

When literary discipline intersects with computational logic, experimentation takes on a distinctively methodical tone. That is precisely th...