Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import tempfile
|
|
9 |
supported_formats = ['avi', 'mp4', 'mov', 'mkv', 'flv', 'wmv', 'webm', 'mpeg', 'mpg', '3gp']
|
10 |
audio_formats = ['mp3', 'wav', 'aac', 'flac']
|
11 |
gif_formats = ['gif']
|
12 |
-
image_formats = list(Image.SAVE.keys())
|
13 |
|
14 |
def sanitize_filename(filename):
|
15 |
"""Sanitize filename by removing special characters and spaces."""
|
@@ -19,7 +19,8 @@ def sanitize_filename(filename):
|
|
19 |
def get_video_duration(video_path):
|
20 |
"""Get video duration in seconds using ffmpeg."""
|
21 |
probe = ffmpeg.probe(video_path, v='error', select_streams='v:0', show_entries='stream=duration')
|
22 |
-
|
|
|
23 |
|
24 |
def convert_video(video, target_format, conversion_type, time_in_seconds=None):
|
25 |
try:
|
@@ -88,6 +89,14 @@ def main():
|
|
88 |
if video_file:
|
89 |
st.video(video_file)
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
# Select conversion type
|
92 |
conversion_type = st.selectbox(
|
93 |
"Select Conversion Type",
|
@@ -100,7 +109,12 @@ def main():
|
|
100 |
|
101 |
# If 'Video to Image' conversion, ask for time in seconds
|
102 |
if conversion_type == 'Video to Image':
|
103 |
-
time_in_seconds = st.
|
|
|
|
|
|
|
|
|
|
|
104 |
else:
|
105 |
time_in_seconds = None
|
106 |
|
|
|
9 |
supported_formats = ['avi', 'mp4', 'mov', 'mkv', 'flv', 'wmv', 'webm', 'mpeg', 'mpg', '3gp']
|
10 |
audio_formats = ['mp3', 'wav', 'aac', 'flac']
|
11 |
gif_formats = ['gif']
|
12 |
+
image_formats = sorted(list(Image.SAVE.keys()))
|
13 |
|
14 |
def sanitize_filename(filename):
|
15 |
"""Sanitize filename by removing special characters and spaces."""
|
|
|
19 |
def get_video_duration(video_path):
|
20 |
"""Get video duration in seconds using ffmpeg."""
|
21 |
probe = ffmpeg.probe(video_path, v='error', select_streams='v:0', show_entries='stream=duration')
|
22 |
+
duration_in_seconds = float(probe['streams'][0]['duration'])
|
23 |
+
return duration_in_seconds
|
24 |
|
25 |
def convert_video(video, target_format, conversion_type, time_in_seconds=None):
|
26 |
try:
|
|
|
89 |
if video_file:
|
90 |
st.video(video_file)
|
91 |
|
92 |
+
# Create a temporary file and save uploaded video
|
93 |
+
temp_video_path = os.path.join(tempfile.mkdtemp(), video_file.name)
|
94 |
+
with open(temp_video_path, "wb") as f:
|
95 |
+
f.write(video_file.getbuffer())
|
96 |
+
|
97 |
+
# Get video duration
|
98 |
+
video_duration = get_video_duration(temp_video_path)
|
99 |
+
|
100 |
# Select conversion type
|
101 |
conversion_type = st.selectbox(
|
102 |
"Select Conversion Type",
|
|
|
109 |
|
110 |
# If 'Video to Image' conversion, ask for time in seconds
|
111 |
if conversion_type == 'Video to Image':
|
112 |
+
time_in_seconds = st.slider(
|
113 |
+
"Time (in seconds) for image extraction",
|
114 |
+
min_value=0,
|
115 |
+
max_value=video_duration,
|
116 |
+
step=1
|
117 |
+
)
|
118 |
else:
|
119 |
time_in_seconds = None
|
120 |
|