Spaces:
Sleeping
Sleeping
Update video_processing.py
Browse files- video_processing.py +8 -0
video_processing.py
CHANGED
@@ -8,6 +8,7 @@ import torch
|
|
8 |
import yt_dlp
|
9 |
from PIL import Image
|
10 |
import uuid
|
|
|
11 |
|
12 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
13 |
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to(device)
|
@@ -30,7 +31,14 @@ def download_video(url):
|
|
30 |
def sanitize_filename(filename):
|
31 |
return "".join([c if c.isalnum() or c in " .-_()" else "_" for c in filename])
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def find_scenes(video_path):
|
|
|
34 |
video_manager = open_video(video_path)
|
35 |
scene_manager = SceneManager()
|
36 |
scene_manager.add_detector(ContentDetector(threshold=30.0))
|
|
|
8 |
import yt_dlp
|
9 |
from PIL import Image
|
10 |
import uuid
|
11 |
+
import subprocess
|
12 |
|
13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to(device)
|
|
|
31 |
def sanitize_filename(filename):
|
32 |
return "".join([c if c.isalnum() or c in " .-_()" else "_" for c in filename])
|
33 |
|
34 |
+
def ensure_video_format(video_path):
|
35 |
+
temp_path = f"temp_videos/formatted_{uuid.uuid4()}.mp4"
|
36 |
+
command = ['ffmpeg', '-i', video_path, '-c', 'copy', temp_path]
|
37 |
+
subprocess.run(command, check=True)
|
38 |
+
return temp_path
|
39 |
+
|
40 |
def find_scenes(video_path):
|
41 |
+
video_path = ensure_video_format(video_path)
|
42 |
video_manager = open_video(video_path)
|
43 |
scene_manager = SceneManager()
|
44 |
scene_manager.add_detector(ContentDetector(threshold=30.0))
|