Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_clip_speaker(clip, transcript):
from openai import OpenAI

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024 * 1024 # 2 GB upload limit

# ─── APP CONFIG ──────────────────────────────────────────
_config_path = "config.json"
Expand Down Expand Up @@ -311,9 +312,13 @@ def do_transcribe():
if os.path.getsize(filepath) > 25 * 1024 * 1024:
progress.update(phase="transcribe", current=0, total=3, message="compressing audio…")
compressed = filepath.rsplit(".", 1)[0] + "_compressed.mp3"
# Calculate bitrate to keep output under 24 MB regardless of duration
duration = progress["audio_duration"] or 1
target_bits = 24 * 1024 * 1024 * 8
bitrate_kbps = max(8, min(64, int(target_bits / duration / 1000)))
subprocess.run([
"ffmpeg", "-y", "-i", filepath,
"-ac", "1", "-ar", "16000", "-b:a", "64k",
"-ac", "1", "-ar", "16000", "-b:a", f"{bitrate_kbps}k",
compressed
], capture_output=True, check=True)
upload_path = compressed
Expand Down Expand Up @@ -745,9 +750,18 @@ def do_process():
if os.path.getsize(filepath) > 25 * 1024 * 1024:
progress.update(phase="narration", current=0, total=3, message="compressing narration…")
compressed = filepath.rsplit(".", 1)[0] + "_compressed.mp3"
try:
dur_result = subprocess.run(
["ffprobe", "-v", "quiet", "-show_entries", "format=duration", "-of", "csv=p=0", filepath],
capture_output=True, text=True)
narr_duration = float(dur_result.stdout.strip()) or 1
except Exception:
narr_duration = 1
target_bits = 24 * 1024 * 1024 * 8
bitrate_kbps = max(8, min(64, int(target_bits / narr_duration / 1000)))
subprocess.run([
"ffmpeg", "-y", "-i", filepath,
"-ac", "1", "-ar", "16000", "-b:a", "64k",
"-ac", "1", "-ar", "16000", "-b:a", f"{bitrate_kbps}k",
compressed
], capture_output=True, check=True)
upload_path = compressed
Expand Down
Loading