Files
TalkEdit/backend/video_editor.py

77 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""
Video editing operations using FFmpeg.
"""
import json
import sys
from pathlib import Path
# Add backend to path
sys.path.insert(0, str(Path(__file__).parent))
from services.video_editor import export_stream_copy, export_reencode, export_reencode_with_subs, get_video_info
def main():
if len(sys.argv) < 2:
print("Usage: python video_editor.py <command> [args...]", file=sys.stderr)
sys.exit(1)
command = sys.argv[1]
try:
if command == "export_stream_copy":
if len(sys.argv) != 5:
print("Usage: python video_editor.py export_stream_copy <input_path> <output_path> <keep_segments_json>", file=sys.stderr)
sys.exit(1)
input_path = sys.argv[2]
output_path = sys.argv[3]
keep_segments = json.loads(sys.argv[4])
result = export_stream_copy(input_path, output_path, keep_segments)
print(json.dumps({"output_path": result}))
elif command == "export_reencode":
if len(sys.argv) != 7:
print("Usage: python video_editor.py export_reencode <input_path> <output_path> <keep_segments_json> <resolution> <format_hint>", file=sys.stderr)
sys.exit(1)
input_path = sys.argv[2]
output_path = sys.argv[3]
keep_segments = json.loads(sys.argv[4])
resolution = sys.argv[5]
format_hint = sys.argv[6]
result = export_reencode(input_path, output_path, keep_segments, resolution, format_hint)
print(json.dumps({"output_path": result}))
elif command == "export_reencode_with_subs":
if len(sys.argv) != 8:
print("Usage: python video_editor.py export_reencode_with_subs <input_path> <output_path> <keep_segments_json> <subtitle_path> <resolution> <format_hint>", file=sys.stderr)
sys.exit(1)
input_path = sys.argv[2]
output_path = sys.argv[3]
keep_segments = json.loads(sys.argv[4])
subtitle_path = sys.argv[5]
resolution = sys.argv[6]
format_hint = sys.argv[7]
result = export_reencode_with_subs(input_path, output_path, keep_segments, subtitle_path, resolution, format_hint)
print(json.dumps({"output_path": result}))
elif command == "get_video_info":
if len(sys.argv) != 3:
print("Usage: python video_editor.py get_video_info <input_path>", file=sys.stderr)
sys.exit(1)
input_path = sys.argv[2]
result = get_video_info(input_path)
print(json.dumps(result))
else:
print(f"Unknown command: {command}", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}), file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()