Update app.py
Browse files
app.py
CHANGED
|
@@ -206,9 +206,20 @@ def interpolate_video_frames(
|
|
| 206 |
output_fps=hardcoded_fps,
|
| 207 |
desired_duration=hardcoded_duration_sec,
|
| 208 |
original_duration=hardcoded_duration_sec,
|
| 209 |
-
|
|
|
|
|
|
|
| 210 |
verbose=False):
|
|
|
|
| 211 |
scale_factor = desired_duration / original_duration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
# note: from all fact, it looks like using a small macroblock is important for us,
|
| 213 |
# since the video resolution is very small (usually 512x288px)
|
| 214 |
interpolation_filter = f'minterpolate=mi_mode=mci:mc_mode=obmc:me=hexbs:vsbmc=1:mb_size=4:fps={output_fps}:scd=none,setpts={scale_factor}*PTS'
|
|
@@ -221,6 +232,13 @@ def interpolate_video_frames(
|
|
| 221 |
#- `scd=none`: Disables scene change detection entirely.
|
| 222 |
#- `setpts={scale_factor}*PTS`: Adjusts for the stretching of the video duration.
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
cmd = [
|
| 225 |
'ffmpeg',
|
| 226 |
'-i', input_file_path,
|
|
@@ -230,7 +248,7 @@ def interpolate_video_frames(
|
|
| 230 |
cmd.extend(['-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda'])
|
| 231 |
|
| 232 |
cmd.extend([
|
| 233 |
-
'-filter:v',
|
| 234 |
'-r', str(output_fps),
|
| 235 |
output_file_path
|
| 236 |
])
|
|
|
|
| 206 |
output_fps=hardcoded_fps,
|
| 207 |
desired_duration=hardcoded_duration_sec,
|
| 208 |
original_duration=hardcoded_duration_sec,
|
| 209 |
+
output_width=1024,
|
| 210 |
+
output_height=576,
|
| 211 |
+
use_cuda=False, # this requires FFmpeg to have been compiled with CUDA support (to try - I'm not sure the Hugging Face image has that by default)
|
| 212 |
verbose=False):
|
| 213 |
+
|
| 214 |
scale_factor = desired_duration / original_duration
|
| 215 |
+
|
| 216 |
+
filters = []
|
| 217 |
+
|
| 218 |
+
# Scaling if dimensions are provided
|
| 219 |
+
if output_width and output_height:
|
| 220 |
+
filters.append(f'scale={output_width}:{output_height}')
|
| 221 |
+
|
| 222 |
+
|
| 223 |
# note: from all fact, it looks like using a small macroblock is important for us,
|
| 224 |
# since the video resolution is very small (usually 512x288px)
|
| 225 |
interpolation_filter = f'minterpolate=mi_mode=mci:mc_mode=obmc:me=hexbs:vsbmc=1:mb_size=4:fps={output_fps}:scd=none,setpts={scale_factor}*PTS'
|
|
|
|
| 232 |
#- `scd=none`: Disables scene change detection entirely.
|
| 233 |
#- `setpts={scale_factor}*PTS`: Adjusts for the stretching of the video duration.
|
| 234 |
|
| 235 |
+
# Frame interpolation setup
|
| 236 |
+
filters.append(interpolation_filter)
|
| 237 |
+
|
| 238 |
+
# Combine all filters into a single filter complex
|
| 239 |
+
filter_complex = ','.join(filters)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
cmd = [
|
| 243 |
'ffmpeg',
|
| 244 |
'-i', input_file_path,
|
|
|
|
| 248 |
cmd.extend(['-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda'])
|
| 249 |
|
| 250 |
cmd.extend([
|
| 251 |
+
'-filter:v', filter_complex,
|
| 252 |
'-r', str(output_fps),
|
| 253 |
output_file_path
|
| 254 |
])
|