youssef
commited on
Commit
·
abf26d0
1
Parent(s):
b841197
remove cuda ffmpeg
Browse files- Dockerfile +0 -2
- src/video_processor/processor.py +10 -37
Dockerfile
CHANGED
|
@@ -23,8 +23,6 @@ RUN apt-get update && \
|
|
| 23 |
liblzma-dev \
|
| 24 |
# gradio dependencies \
|
| 25 |
ffmpeg \
|
| 26 |
-
# NVIDIA Video Codec SDK \
|
| 27 |
-
libnvidia-encode-12-3 \
|
| 28 |
&& apt-get clean \
|
| 29 |
&& rm -rf /var/lib/apt/lists/*
|
| 30 |
|
|
|
|
| 23 |
liblzma-dev \
|
| 24 |
# gradio dependencies \
|
| 25 |
ffmpeg \
|
|
|
|
|
|
|
| 26 |
&& apt-get clean \
|
| 27 |
&& rm -rf /var/lib/apt/lists/*
|
| 28 |
|
src/video_processor/processor.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 3 |
-
from typing import List, Dict
|
| 4 |
import logging
|
| 5 |
import os
|
| 6 |
import subprocess
|
|
@@ -103,7 +103,7 @@ Be specific about visual details but stay concise."""}
|
|
| 103 |
)
|
| 104 |
return self.processor.batch_decode(outputs, skip_special_tokens=True)[0].split("Assistant: ")[-1]
|
| 105 |
|
| 106 |
-
def process_video(self, video_path: str, segment_length: int = 10) ->
|
| 107 |
try:
|
| 108 |
# Create temp directory for segments
|
| 109 |
temp_dir = tempfile.mkdtemp()
|
|
@@ -128,49 +128,22 @@ Be specific about visual details but stay concise."""}
|
|
| 128 |
cmd = [
|
| 129 |
"ffmpeg",
|
| 130 |
"-y", # Overwrite output files
|
| 131 |
-
"-
|
| 132 |
-
"-hwaccel_output_format", "cuda", # Keep frames in GPU memory
|
| 133 |
-
"-threads", "0", # Use all available CPU threads
|
| 134 |
-
"-thread_type", "frame", # Frame-level multi-threading
|
| 135 |
"-i", video_path,
|
| 136 |
"-ss", str(start_time), # Seek position
|
| 137 |
"-t", str(end_time - start_time), # Duration
|
| 138 |
-
"-c:v", "
|
| 139 |
-
"-preset", "
|
| 140 |
-
"-tune", "
|
| 141 |
-
"-
|
| 142 |
-
"-
|
| 143 |
-
"-b:v", "0", # Let VBR control bitrate
|
| 144 |
-
"-vf", "scale_cuda=640:-2", # GPU-accelerated scaling
|
| 145 |
"-an", # Remove audio
|
|
|
|
| 146 |
segment_path
|
| 147 |
]
|
| 148 |
|
| 149 |
ffmpeg_start = time.time()
|
| 150 |
-
|
| 151 |
-
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 152 |
-
logger.debug(f"FFmpeg output: {result.stderr}")
|
| 153 |
-
except subprocess.CalledProcessError as e:
|
| 154 |
-
logger.error(f"FFmpeg error: {e.stderr}")
|
| 155 |
-
# Fallback to CPU if GPU encoding fails
|
| 156 |
-
logger.warning("Falling back to CPU encoding")
|
| 157 |
-
cmd = [
|
| 158 |
-
"ffmpeg",
|
| 159 |
-
"-y",
|
| 160 |
-
"-threads", "0",
|
| 161 |
-
"-i", video_path,
|
| 162 |
-
"-ss", str(start_time),
|
| 163 |
-
"-t", str(end_time - start_time),
|
| 164 |
-
"-c:v", "libx264",
|
| 165 |
-
"-preset", "ultrafast",
|
| 166 |
-
"-tune", "fastdecode",
|
| 167 |
-
"-crf", "28",
|
| 168 |
-
"-vf", "scale=640:-2",
|
| 169 |
-
"-an",
|
| 170 |
-
"-pix_fmt", "yuv420p",
|
| 171 |
-
segment_path
|
| 172 |
-
]
|
| 173 |
-
subprocess.run(cmd, check=True, capture_output=True)
|
| 174 |
ffmpeg_time = time.time() - ffmpeg_start
|
| 175 |
|
| 176 |
# Analyze segment
|
|
|
|
| 1 |
import torch
|
| 2 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 3 |
+
from typing import List, Dict
|
| 4 |
import logging
|
| 5 |
import os
|
| 6 |
import subprocess
|
|
|
|
| 103 |
)
|
| 104 |
return self.processor.batch_decode(outputs, skip_special_tokens=True)[0].split("Assistant: ")[-1]
|
| 105 |
|
| 106 |
+
def process_video(self, video_path: str, segment_length: int = 10) -> List[Dict]:
|
| 107 |
try:
|
| 108 |
# Create temp directory for segments
|
| 109 |
temp_dir = tempfile.mkdtemp()
|
|
|
|
| 128 |
cmd = [
|
| 129 |
"ffmpeg",
|
| 130 |
"-y", # Overwrite output files
|
| 131 |
+
"-threads", "4", # Use 4 threads
|
|
|
|
|
|
|
|
|
|
| 132 |
"-i", video_path,
|
| 133 |
"-ss", str(start_time), # Seek position
|
| 134 |
"-t", str(end_time - start_time), # Duration
|
| 135 |
+
"-c:v", "libx264", # Video codec
|
| 136 |
+
"-preset", "ultrafast",
|
| 137 |
+
"-tune", "fastdecode",
|
| 138 |
+
"-crf", "28", # Lower quality but faster
|
| 139 |
+
"-vf", "scale=640:-2", # Resize to smaller resolution
|
|
|
|
|
|
|
| 140 |
"-an", # Remove audio
|
| 141 |
+
"-pix_fmt", "yuv420p",
|
| 142 |
segment_path
|
| 143 |
]
|
| 144 |
|
| 145 |
ffmpeg_start = time.time()
|
| 146 |
+
subprocess.run(cmd, check=True, capture_output=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
ffmpeg_time = time.time() - ffmpeg_start
|
| 148 |
|
| 149 |
# Analyze segment
|