20 lines
667 B
Python
20 lines
667 B
Python
"""Stream-copy an .mkv into an .mp4 so Discord can play it inline (no re-encode)."""
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def remux_to_mp4(src: Path, dst: Path, timeout: int = 1800) -> bool:
|
|
cmd = [
|
|
"ffmpeg", "-v", "error", "-y", "-i", str(src),
|
|
"-map", "0:v", "-map", "0:a?", "-c", "copy",
|
|
"-movflags", "+faststart", str(dst),
|
|
]
|
|
try:
|
|
result = subprocess.run(cmd, capture_output=True, timeout=timeout)
|
|
ok = result.returncode == 0 and dst.exists() and dst.stat().st_size > 0
|
|
except (OSError, subprocess.TimeoutExpired):
|
|
ok = False
|
|
if not ok:
|
|
dst.unlink(missing_ok=True)
|
|
return ok
|