Dari nol sampai video pertama — Kling AI + FLUX + Edge TTS + FFmpeg
Pipeline otomatis: dari 1 foto + 1 topik → video 30 detik siap upload ke 4 platform.
| Tahap | Tool | Biaya | Waktu |
|---|---|---|---|
| 1. Generate Script | mimo-v2.5 | GRATIS | 2 detik |
| 2. Generate Gambar | FLUX (Replicate API) | $0.01/gambar | 3-5 detik |
| 3. Generate Video | Kling AI API | $2.80-4.00 | 30-60 detik |
| 4. Generate Voiceover | Edge TTS | GRATIS | 3-5 detik |
| 5. Assembly | FFmpeg | GRATIS | 5-10 detik |
| 6. Export Multi-Platform | FFmpeg | GRATIS | 3-5 detik |
| TOTAL | $2.82-4.06/video | ~2 menit |
Setup tools dan API keys yang dibutuhkan.
# SSH ke VPS
ssh -i ~/.ssh/id_ed25519_to_204 ubuntu@43.157.204.29
# Install tools
sudo apt update && sudo apt install -y ffmpeg python3-pip
# Install Python packages
pip3 install edge-tts replicate requests
# Verify
ffmpeg -version | head -1
python3 -c "import edge_tts; print('edge-tts OK')"
python3 -c "import replicate; print('replicate OK')"
| API | Daftar di | Biaya | Catatan |
|---|---|---|---|
| Kling AI | https://klingai.com | $8-28/bulan | Pilih Standard plan dulu ($8/bln = 660 kredit) |
| Replicate (FLUX) | https://replicate.com | $0.01/gambar | Bayar per use, no subscription |
| Edge TTS | Tidak perlu daftar | GRATIS | Microsoft Edge built-in, no API key |
| FFmpeg | Sudah ada di VPS | GRATIS | Install via apt |
Kling belum punya API publik resmi seperti OpenAI. Alternatif:
Rekomendasi: Mulai dengan Replicate + Wan2.1 (API publik, $0.05/detik) — mirip kualitas Kling, lebih mudah di-automate.
# Buat file env
cat > ~/.video-pipeline/.env <<'EOF'
KLING_API_KEY=your_kling_api_key_here
KLING_API_SECRET=your_kling_secret_here
REPLICATE_API_TOKEN=r8_your_replicate_token
WHATSAPP_NUMBER=6282112685085
EOF
# Restrict access
chmod 600 ~/.video-pipeline/.env
Script utama yang menjalankan seluruh pipeline secara otomatis.
#!/usr/bin/env python3
"""
Panorama Digital AI — Video Pipeline
Dari foto + topik → video 30 detik siap upload
"""
import os, json, asyncio, subprocess, time, random
from pathlib import Path
import requests
import edge_tts
from dotenv import load_dotenv
load_dotenv()
# === CONFIG ===
REPLICATE_TOKEN = os.getenv("REPLICATE_API_TOKEN")
KLING_KEY = os.getenv("KLING_API_KEY")
OUTPUT_DIR = Path("output")
ASSETS_DIR = Path("assets")
OUTPUT_DIR.mkdir(exist_ok=True)
# Voice settings per host
HOSTS = {
"fernando": {"voice": "id-ID-ArdiNeural", "rate": "+0%"},
"ahmad": {"voice": "id-ID-ArdiNeural", "rate": "-5%"},
"siti": {"voice": "id-ID-GadisNeural", "rate": "+0%"},
}
# === STEP 1: GENERATE SCRIPT ===
def generate_script(topic: str, host: str = "fernando") -> dict:
"""Generate narasi + deskripsi visual per scene"""
# Untuk MVP, pakai template. Nanti bisa ganti ke mimo API.
prompts = {
"umroh": {
"narration": "Siapkan diri untuk perjalanan suci. Umroh bukan sekadar ibadah, tapi transformasi hidup. Dengan Pandorama Digital, setiap momen menjadi kenangan abadi.",
"scenes": [
"Cinematic aerial view of Masjidil Haram, golden hour, crowd of pilgrims, 4K",
"Close-up of hands holding prayer beads, warm lighting, spiritual atmosphere",
"Pilgrims walking around Kaaba, slow motion, dramatic sky",
]
},
"travel": {
"narration": "Jelajahi keindahan dunia bersama Panorama Tour. Dari puncak gunung hingga dasar laut, setiap destinasi punya cerita.",
"scenes": [
"Beautiful tropical beach, crystal clear water, drone shot, paradise",
"Mountain landscape at sunrise, misty clouds, epic view",
"Underwater coral reef, tropical fish, vibrant colors",
]
}
}
return prompts.get(topic, prompts["umroh"])
# === STEP 2: GENERATE GAMBAR (FLUX via Replicate) ===
def generate_image(prompt: str) -> str:
"""Generate gambar dari prompt pakai FLUX"""
response = requests.post(
"https://api.replicate.com/v1/predictions",
headers={
"Authorization": f"Token {REPLICATE_TOKEN}",
"Content-Type": "application/json"
},
json={
"version": "black-forest-labs/flux-schnell",
"input": {
"prompt": prompt,
"num_outputs": 1,
"aspect_ratio": "16:9",
"output_format": "webp",
"output_quality": 90
}
}
)
prediction = response.json()
# Poll sampai selesai
while prediction["status"] not in ["succeeded", "failed"]:
time.sleep(2)
prediction = requests.get(
prediction["urls"]["get"],
headers={"Authorization": f"Token {REPLICATE_TOKEN}"}
).json()
if prediction["status"] == "succeeded":
return prediction["output"][0] # URL gambar
raise Exception(f"Image gen failed: {prediction}")
# === STEP 3: GENERATE VIDEO (Wan2.1 via Replicate) ===
def generate_video(image_url: str) -> str:
"""Generate video 5 detik dari gambar pakai Wan2.1"""
response = requests.post(
"https://api.replicate.com/v1/predictions",
headers={
"Authorization": f"Token {REPLICATE_TOKEN}",
"Content-Type": "application/json"
},
json={
"version": "wan-ai/wan2.1-i2v-14b-720p",
"input": {
"image": image_url,
"prompt": "cinematic camera movement, smooth, professional",
"num_frames": 81, # ~5 detik @ 16fps
"guidance_scale": 5.0,
}
}
)
prediction = response.json()
# Poll sampai selesai (video lebih lama)
while prediction["status"] not in ["succeeded", "failed"]:
time.sleep(5)
prediction = requests.get(
prediction["urls"]["get"],
headers={"Authorization": f"Token {REPLICATE_TOKEN}"}
).json()
if prediction["status"] == "succeeded":
return prediction["output"] # URL video
raise Exception(f"Video gen failed: {prediction}")
# === STEP 4: GENERATE VOICEOVER (Edge TTS) ===
async def generate_voiceover(text: str, host: str = "fernando") -> str:
"""Generate voiceover gratis pakai Edge TTS"""
voice_cfg = HOSTS.get(host, HOSTS["fernando"])
output_path = OUTPUT_DIR / "temp_voiceover.mp3"
communicate = edge_tts.Communicate(
text,
voice_cfg["voice"],
rate=voice_cfg["rate"]
)
await communicate.save(str(output_path))
return str(output_path)
# === STEP 5: ASSEMBLY (FFmpeg) ===
def assemble_video(clips: list, voiceover: str, topic: str) -> str:
"""Gabung semua clip + audio jadi 1 video"""
# Buat concat file
concat_file = OUTPUT_DIR / "concat.txt"
with open(concat_file, "w") as f:
for clip in clips:
f.write(f"file '{clip}'\n")
# Gabung video clips
merged_video = OUTPUT_DIR / "merged_video.mp4"
subprocess.run([
"ffmpeg", "-y",
"-f", "concat",
"-safe", "0",
"-i", str(concat_file),
"-c:v", "libx264",
"-preset", "fast",
"-crf", "18",
str(merged_video)
], check=True)
# Tambah audio voiceover
final_output = OUTPUT_DIR / f"final_{topic}_{int(time.time())}.mp4"
subprocess.run([
"ffmpeg", "-y",
"-i", str(merged_video),
"-i", voiceover,
"-c:v", "copy",
"-c:a", "aac",
"-shortest",
str(final_output)
], check=True)
return str(final_output)
# === STEP 6: EXPORT MULTI-FORMAT ===
def export_formats(video_path: str) -> dict:
"""Export ke berbagai format untuk platform berbeda"""
exports = {}
base = Path(video_path).stem
formats = {
"youtube": {"w": 1920, "h": 1080},
"tiktok": {"w": 1080, "h": 1920},
"instagram": {"w": 1080, "h": 1920},
"facebook": {"w": 1080, "h": 1080},
}
for platform, size in formats.items():
out = OUTPUT_DIR / f"{base}_{platform}.mp4"
subprocess.run([
"ffmpeg", "-y",
"-i", video_path,
"-vf", f"scale={size['w']}:{size['h']}:force_original_aspect_ratio=decrease,pad={size['w']}:{size['h']}:(ow-iw)/2:(oh-ih)/2",
"-c:v", "libx264",
"-preset", "fast",
"-crf", "23",
"-c:a", "aac",
str(out)
], check=True)
exports[platform] = str(out)
return exports
# === MAIN PIPELINE ===
async def run_pipeline(topic: str, host: str = "fernando"):
"""Jalankan seluruh pipeline"""
print(f"\n🎬 Starting pipeline: {topic} (host: {host})")
# Step 1: Script
print("📝 Step 1: Generating script...")
script = generate_script(topic, host)
# Step 2: Generate gambar per scene
print("🖼️ Step 2: Generating images...")
images = []
for i, scene in enumerate(script["scenes"]):
print(f" Scene {i+1}/{len(script['scenes'])}: {scene[:50]}...")
img_url = generate_image(scene)
images.append(img_url)
print(f" ✅ Image: {img_url[:60]}...")
# Step 3: Generate video per scene
print("🎥 Step 3: Generating videos...")
clips = []
for i, img in enumerate(images):
print(f" Clip {i+1}/{len(images)}: Generating 5s video...")
video_url = generate_video(img)
# Download clip
clip_path = OUTPUT_DIR / f"clip_{i}.mp4"
r = requests.get(video_url)
with open(clip_path, "wb") as f:
f.write(r.content)
clips.append(str(clip_path))
print(f" ✅ Clip {i+1} saved")
# Step 4: Voiceover
print("🎙️ Step 4: Generating voiceover...")
voiceover = await generate_voiceover(script["narration"], host)
print(" ✅ Voiceover ready")
# Step 5: Assembly
print("🔧 Step 5: Assembling video...")
final_video = assemble_video(clips, voiceover, topic)
print(f" ✅ Final video: {final_video}")
# Step 6: Export
print("📤 Step 6: Exporting multi-format...")
exports = export_formats(final_video)
for platform, path in exports.items():
print(f" ✅ {platform}: {path}")
print(f"\n🎉 Pipeline selesai! Total video: {len(exports) + 1}")
return exports
# === RUN ===
if __name__ == "__main__":
asyncio.run(run_pipeline("umroh", "fernando"))
Kalau pakai Kling API: ~$2.80-4.00/video (kualitas lebih baik)
Test dengan 1 video dulu, lalu scale.
# Masuk ke directory
cd ~/.video-pipeline
# Jalankan pipeline untuk topik umroh
python3 pipeline.py
# Output akan ada di output/
ls -la output/
# final_umroh_1725012345.mp4
# final_umroh_1725012345_youtube.mp4
# final_umroh_1725012345_tiktok.mp4
# final_umroh_1725012345_instagram.mp4
# final_umroh_1725012345_facebook.mp4
# Umroh - Fernando
python3 -c "import asyncio; from pipeline import run_pipeline; asyncio.run(run_pipeline('umroh', 'fernando'))"
# Travel - Siti
python3 -c "import asyncio; from pipeline import run_pipeline; asyncio.run(run_pipeline('travel', 'siti'))"
# Islami - Ahmad
python3 -c "import asyncio; from pipeline import run_pipeline; asyncio.run(run_pipeline('islami', 'ahmad'))"
Jalankan pipeline otomatis setiap hari via Hermes scheduler.
# Buat cron job untuk jalankan pipeline setiap hari jam 8 pagi
# Prompt ke Hermes: generate 5 video per hari
hermes cron create \
--schedule "0 8 * * *" \
--prompt "Jalankan video pipeline: generate 5 video umroh/travel dengan topik berbeda. Setelah selesai, list file di output/ lalu summary berapa video yang berhasil."
Setelah pipeline jalan dan ada revenue, upgrade ke:
| Upgrade | Biaya | Impact |
|---|---|---|
| Ganti Wan2.1 → Kling Pro | $4-6/video | Kualitas naik signifikan, motion lebih natural |
| Tambah mimo API untuk script | GRATIS | Script lebih variatif, tidak template-based |
| Tambah LoRA training untuk host | $50 sekali (GPU rent) | Wajah host konsisten 100% |
| Beli RTX 4090 ($1,600) | $1,600 + $30/bulan listrik | Self-hosted, cost turun ke $0.15/video |
| Tambah Suno API untuk musik | $0.50/music | Background music original, no copyright issue |
1. Daftar Replicate + Kling (5 menit)
2. Jalankan pipeline.py (1 menit)
3. Video pertama jadi dalam ~2 menit
4. Upload ke YouTube/TikTok