Ahmadkhan12 commited on
Commit
a5bc70f
·
verified ·
1 Parent(s): 0d5fbd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -1,35 +1,33 @@
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
8
- vr = decord.VideoReader(video_path)
9
- fps = vr.get_avg_fps()
10
- total_frames = len(vr)
11
- duration = total_frames / fps
 
 
 
 
12
 
13
  # Calculate the number of chunks
14
  num_chunks = int(duration // chunk_duration)
15
 
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)
@@ -47,8 +45,7 @@ def process_video(video):
47
 
48
  # Gradio Interface
49
  def gradio_interface(video):
50
- chunk_files = process_video(video)
51
- return chunk_files
52
 
53
  # Define Gradio app
54
  iface = gr.Interface(
 
 
1
  import os
 
2
  import subprocess
3
+ import gradio as gr
4
 
5
  def split_video_into_chunks(video_path, chunk_duration=6, output_dir="video_chunks"):
6
+ # Create output directory
7
+ os.makedirs(output_dir, exist_ok=True)
8
+
9
+ # Get video duration using FFmpeg
10
+ cmd_duration = [
11
+ "ffprobe", "-v", "error", "-show_entries", "format=duration",
12
+ "-of", "default=noprint_wrappers=1:nokey=1", video_path
13
+ ]
14
+ duration = float(subprocess.run(cmd_duration, capture_output=True, text=True).stdout.strip())
15
 
16
  # Calculate the number of chunks
17
  num_chunks = int(duration // chunk_duration)
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
  output_file = os.path.join(output_dir, f"chunk_{i+1}.mp4")
24
 
25
  # FFmpeg command to extract the chunk
26
  command = [
27
+ "ffmpeg", "-i", video_path,
 
28
  "-ss", str(start_time),
29
  "-t", str(chunk_duration),
30
+ "-c", "copy", # Copy codec (no re-encoding)
31
  output_file
32
  ]
33
  subprocess.run(command, check=True)
 
45
 
46
  # Gradio Interface
47
  def gradio_interface(video):
48
+ return process_video(video)
 
49
 
50
  # Define Gradio app
51
  iface = gr.Interface(