GenAIJake commited on
Commit
4b426e1
1 Parent(s): fd758d8
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -8,12 +8,30 @@ def process_video(video_path, nframes, height, width, direction, trim, average,
8
  try:
9
  fv = FrameVis()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Process the video
12
  output_image = fv.visualize(
13
  video_path,
14
  nframes=nframes,
15
- height=height if height > 0 else None,
16
- width=width if width > 0 else None,
17
  direction=direction,
18
  trim=trim,
19
  quiet=False
@@ -37,7 +55,7 @@ with gr.Blocks(title="FrameVis - Video Frame Visualizer") as demo:
37
  gr.Markdown("""
38
  # 🎬 FrameVis - Video Frame Visualizer
39
  Upload a video to create a beautiful visualization of its frames. The tool will extract frames at regular intervals
40
- and combine them into a single image.
41
  """)
42
 
43
  with gr.Row():
@@ -45,7 +63,7 @@ with gr.Blocks(title="FrameVis - Video Frame Visualizer") as demo:
45
  # Input components
46
  video_input = gr.Video(label="Upload Video")
47
  with gr.Row():
48
- nframes = gr.Slider(minimum=1, maximum=500, value=100, step=1,
49
  label="Number of Frames")
50
  direction = gr.Radio(["horizontal", "vertical"], value="horizontal",
51
  label="Direction")
@@ -64,7 +82,7 @@ with gr.Blocks(title="FrameVis - Video Frame Visualizer") as demo:
64
 
65
  with gr.Column(scale=2):
66
  # Output component
67
- output_image = gr.Image(label="Visualization Result", height=300)
68
 
69
  # Handle processing
70
  process_btn.click(
 
8
  try:
9
  fv = FrameVis()
10
 
11
+ # Get video properties to calculate appropriate dimensions
12
+ cap = cv2.VideoCapture(video_path)
13
+ video_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
14
+ video_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
15
+ cap.release()
16
+
17
+ # Calculate dimensions to maintain aspect ratio
18
+ if width <= 0:
19
+ # If width is auto, use the video's native width * 2 as a reasonable default
20
+ width = video_width * 2
21
+
22
+ if height <= 0:
23
+ # Calculate height to maintain aspect ratio
24
+ if direction == "horizontal":
25
+ height = int((width / video_width) * video_height)
26
+ else:
27
+ height = video_height
28
+
29
  # Process the video
30
  output_image = fv.visualize(
31
  video_path,
32
  nframes=nframes,
33
+ height=height,
34
+ width=width,
35
  direction=direction,
36
  trim=trim,
37
  quiet=False
 
55
  gr.Markdown("""
56
  # 🎬 FrameVis - Video Frame Visualizer
57
  Upload a video to create a beautiful visualization of its frames. The tool will extract frames at regular intervals
58
+ and combine them into a single image. For best results with horizontal layout, try setting width to match your screen width.
59
  """)
60
 
61
  with gr.Row():
 
63
  # Input components
64
  video_input = gr.Video(label="Upload Video")
65
  with gr.Row():
66
+ nframes = gr.Slider(minimum=1, maximum=2000, value=100, step=1,
67
  label="Number of Frames")
68
  direction = gr.Radio(["horizontal", "vertical"], value="horizontal",
69
  label="Direction")
 
82
 
83
  with gr.Column(scale=2):
84
  # Output component
85
+ output_image = gr.Image(label="Visualization Result")
86
 
87
  # Handle processing
88
  process_btn.click(