fffiloni commited on
Commit
c5fdebd
1 Parent(s): 4ddad9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -109,8 +109,43 @@ def infer(video_in):
109
  # Get the directory name
110
  folder_path = os.path.dirname(video_in)
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # Execute the inference command
113
- command = ['python', 'inference_from_video.py', '--original_args', 'ckpt/vta-ldm-clip4clip-v-large/summary.jsonl', '--model', 'ckpt/vta-ldm-clip4clip-v-large/pytorch_model_2.bin', '--data_path', folder_path]
 
 
 
 
 
114
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
115
 
116
  # Create threads to handle stdout and stderr
 
109
  # Get the directory name
110
  folder_path = os.path.dirname(video_in)
111
 
112
+ # Path to the input video file
113
+ input_video_path = video_in
114
+
115
+ # Load the video file
116
+ video = VideoFileClip(input_video_path)
117
+
118
+ # Get the length of the video in seconds
119
+ video_duration = video.duration
120
+ print(f"Video duration: {video_duration} seconds")
121
+
122
+ # Check if the video duration is more than 10 seconds
123
+ if video_duration > 10:
124
+ # Cut the video to the first 10 seconds
125
+ cut_video = video.subclip(0, 10)
126
+ video_duration = 10
127
+
128
+ # Extract the directory and filename
129
+ dir_name = os.path.dirname(input_video_path)
130
+ base_name = os.path.basename(input_video_path)
131
+
132
+ # Generate the new filename
133
+ new_base_name = base_name.replace(".mp4", "_10sec_cut.mp4")
134
+ output_video_path = os.path.join(dir_name, new_base_name)
135
+
136
+ # Save the cut video
137
+ cut_video.write_videofile(output_video_path, codec='libx264', audio_codec='aac')
138
+ print(f"Cut video saved as: {output_video_path}")
139
+ else:
140
+ print("Video is 10 seconds or shorter; no cutting needed.")
141
+
142
  # Execute the inference command
143
+ command = ['python', 'inference_from_video.py',
144
+ '--original_args', 'ckpt/vta-ldm-clip4clip-v-large/summary.jsonl',
145
+ '--model', 'ckpt/vta-ldm-clip4clip-v-large/pytorch_model_2.bin',
146
+ '--data_path', folder_path,
147
+ '--max_duration', video_duration
148
+ ]
149
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
150
 
151
  # Create threads to handle stdout and stderr