casperarmani commited on
Commit ·
c62236d
1
Parent(s): 4e4e870
Use lossless ffmpeg copy when trimming inputs
Browse files- gradio_app.py +23 -3
gradio_app.py
CHANGED
|
@@ -6,6 +6,7 @@ import datetime
|
|
| 6 |
import shutil
|
| 7 |
from pathlib import Path
|
| 8 |
from moviepy.editor import VideoFileClip
|
|
|
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
# Download Weights
|
|
@@ -64,10 +65,29 @@ propainter = Propainter(propainter_model_dir, device=device)
|
|
| 64 |
# Helper function to trim videos
|
| 65 |
def trim_video(input_path, output_path, max_duration=10):
|
| 66 |
clip = VideoFileClip(input_path)
|
| 67 |
-
|
| 68 |
-
trimmed_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
|
| 69 |
clip.close()
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
@spaces.GPU(duration=1200)
|
| 73 |
def infer(input_video, input_mask):
|
|
|
|
| 6 |
import shutil
|
| 7 |
from pathlib import Path
|
| 8 |
from moviepy.editor import VideoFileClip
|
| 9 |
+
import subprocess
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
# Download Weights
|
|
|
|
| 65 |
# Helper function to trim videos
|
| 66 |
def trim_video(input_path, output_path, max_duration=10):
|
| 67 |
clip = VideoFileClip(input_path)
|
| 68 |
+
duration = min(max_duration, clip.duration)
|
|
|
|
| 69 |
clip.close()
|
| 70 |
+
|
| 71 |
+
# Preserve original encoding to avoid reintroducing H.264 macroblocking artefacts
|
| 72 |
+
subprocess.run(
|
| 73 |
+
[
|
| 74 |
+
"ffmpeg",
|
| 75 |
+
"-hide_banner",
|
| 76 |
+
"-loglevel",
|
| 77 |
+
"error",
|
| 78 |
+
"-y",
|
| 79 |
+
"-ss",
|
| 80 |
+
"0",
|
| 81 |
+
"-i",
|
| 82 |
+
input_path,
|
| 83 |
+
"-t",
|
| 84 |
+
f"{duration:.6f}",
|
| 85 |
+
"-c",
|
| 86 |
+
"copy",
|
| 87 |
+
output_path,
|
| 88 |
+
],
|
| 89 |
+
check=True,
|
| 90 |
+
)
|
| 91 |
|
| 92 |
@spaces.GPU(duration=1200)
|
| 93 |
def infer(input_video, input_mask):
|