Added revisions to the translation app

This commit is contained in:
2026-01-12 08:52:38 -05:00
parent 64add85920
commit 8181bebaa0
44 changed files with 993 additions and 375 deletions
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from utils import verify_file_not_empty
def extract_audio(video_path, output_path=None):
"""
@@ -22,7 +23,7 @@ def extract_audio(video_path, output_path=None):
output_path = f"{base_name}.wav"
# Check if output file already exists to avoid redundant processing
if os.path.exists(output_path):
if verify_file_not_empty(output_path):
print(f"Audio file already exists: {output_path}")
return output_path
@@ -43,11 +44,18 @@ def extract_audio(video_path, output_path=None):
try:
subprocess.run(command, check=True)
if not verify_file_not_empty(output_path):
raise Exception("FFmpeg command succeeded but output file is empty or missing.")
print(f"Audio extracted to: {output_path}")
return output_path
except subprocess.CalledProcessError as e:
print(f"Error extracting audio: {e}")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
def embed_subtitles(video_path, srt_path, output_path=None):
"""
@@ -80,6 +88,7 @@ def embed_subtitles(video_path, srt_path, output_path=None):
command = [
"ffmpeg",
"-ignore_editlist", "1",
"-i", video_path,
"-i", srt_path,
"-map", "0:v",
@@ -90,6 +99,8 @@ def embed_subtitles(video_path, srt_path, output_path=None):
"-disposition:s:0", "default",
"-metadata:s:s:0", "language=eng",
"-metadata:s:s:0", "title=English (AI Translated)",
"-max_interleave_delta", "0",
"-avoid_negative_ts", "make_zero",
"-y",
"-v", "error",
output_path
@@ -97,6 +108,11 @@ def embed_subtitles(video_path, srt_path, output_path=None):
try:
subprocess.run(command, check=True)
if not verify_file_not_empty(output_path):
raise Exception("FFmpeg command succeeded but output video is empty or missing.")
print(f"Subtitles embedded successfully: {output_path} (Set as primary)")
except subprocess.CalledProcessError as e:
print(f"Error embedding subtitles: {e}")
except Exception as e:
print(f"Error embedding subtitles: {e}")