Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import decord
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
|
| 6 |
def split_video_into_chunks(video_path, chunk_duration=6, output_dir="video_chunks"):
|
| 7 |
# Load the video using Decord
|
|
@@ -16,25 +16,23 @@ def split_video_into_chunks(video_path, chunk_duration=6, output_dir="video_chun
|
|
| 16 |
# Create output directory
|
| 17 |
os.makedirs(output_dir, exist_ok=True)
|
| 18 |
|
| 19 |
-
# Split the video into chunks
|
| 20 |
chunk_files = []
|
| 21 |
for i in range(num_chunks):
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Ensure end_frame does not exceed total_frames
|
| 26 |
-
end_frame = min(end_frame, total_frames)
|
| 27 |
-
|
| 28 |
-
# Extract frames for the chunk
|
| 29 |
-
chunk_frames = vr[start_frame:end_frame]
|
| 30 |
-
|
| 31 |
-
# Save the chunk as a new video file
|
| 32 |
output_file = os.path.join(output_dir, f"chunk_{i+1}.mp4")
|
| 33 |
-
chunk_frames = [frame.asnumpy() for frame in chunk_frames] # Convert Decord frames to numpy arrays
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
chunk_files.append(output_file)
|
| 40 |
|
|
|
|
| 1 |
import decord
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
+
import subprocess
|
| 5 |
|
| 6 |
def split_video_into_chunks(video_path, chunk_duration=6, output_dir="video_chunks"):
|
| 7 |
# Load the video using Decord
|
|
|
|
| 16 |
# Create output directory
|
| 17 |
os.makedirs(output_dir, exist_ok=True)
|
| 18 |
|
| 19 |
+
# Split the video into chunks using FFmpeg
|
| 20 |
chunk_files = []
|
| 21 |
for i in range(num_chunks):
|
| 22 |
+
start_time = i * chunk_duration
|
| 23 |
+
end_time = (i + 1) * chunk_duration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
output_file = os.path.join(output_dir, f"chunk_{i+1}.mp4")
|
|
|
|
| 25 |
|
| 26 |
+
# FFmpeg command to extract the chunk
|
| 27 |
+
command = [
|
| 28 |
+
"ffmpeg",
|
| 29 |
+
"-i", video_path,
|
| 30 |
+
"-ss", str(start_time),
|
| 31 |
+
"-t", str(chunk_duration),
|
| 32 |
+
"-c", "copy",
|
| 33 |
+
output_file
|
| 34 |
+
]
|
| 35 |
+
subprocess.run(command, check=True)
|
| 36 |
|
| 37 |
chunk_files.append(output_file)
|
| 38 |
|