Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -88,51 +88,60 @@ def main():
|
|
88 |
st.title("Video Conversion Tool")
|
89 |
st.write("Convert videos to audio, GIFs, images, or other formats easily with this powerful tool.")
|
90 |
|
91 |
-
#
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
# If 'Video to Image' conversion, ask for time in seconds
|
116 |
-
if conversion_type == 'Video to Image':
|
117 |
-
time_in_seconds = st.slider(
|
118 |
-
label="Time (in seconds) for image extraction",
|
119 |
-
min_value=0,
|
120 |
-
max_value=int(video_duration),
|
121 |
-
value=0,
|
122 |
-
step=1
|
123 |
)
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
if __name__ == "__main__":
|
138 |
main()
|
|
|
88 |
st.title("Video Conversion Tool")
|
89 |
st.write("Convert videos to audio, GIFs, images, or other formats easily with this powerful tool.")
|
90 |
|
91 |
+
# Create two columns
|
92 |
+
col1, col2 = st.columns([1, 1])
|
93 |
+
|
94 |
+
with col1:
|
95 |
+
# Upload video file
|
96 |
+
video_file = st.file_uploader("Upload a Video", type=supported_formats)
|
97 |
+
if video_file:
|
98 |
+
st.video(video_file)
|
99 |
+
|
100 |
+
with col2:
|
101 |
+
if video_file:
|
102 |
+
# Create a temporary file and save uploaded video
|
103 |
+
temp_video_path = os.path.join(tempfile.mkdtemp(), video_file.name)
|
104 |
+
with open(temp_video_path, "wb") as f:
|
105 |
+
f.write(video_file.getbuffer())
|
106 |
+
|
107 |
+
# Get video duration
|
108 |
+
video_duration = get_video_duration(temp_video_path)
|
109 |
+
|
110 |
+
# Select conversion type
|
111 |
+
conversion_type = st.selectbox(
|
112 |
+
"Select Conversion Type",
|
113 |
+
['Video to Video', 'Video to Audio', 'Video to GIF', 'Video to Image']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
)
|
115 |
+
|
116 |
+
# Update format choices based on conversion type
|
117 |
+
target_format_choices = update_format_choices(conversion_type)
|
118 |
+
target_format = st.selectbox("Select Target Format", target_format_choices)
|
119 |
+
|
120 |
+
# If 'Video to Image' conversion, ask for time in seconds
|
121 |
+
if conversion_type == 'Video to Image':
|
122 |
+
time_in_seconds = st.slider(
|
123 |
+
label="Time (in seconds) for image extraction",
|
124 |
+
min_value=0,
|
125 |
+
max_value=int(video_duration),
|
126 |
+
value=0,
|
127 |
+
step=1
|
128 |
+
)
|
129 |
+
else:
|
130 |
+
time_in_seconds = None
|
131 |
+
|
132 |
+
if st.button("Convert"):
|
133 |
+
with st.spinner("Converting..."):
|
134 |
+
output_file = convert_video(video_file, target_format, conversion_type, time_in_seconds)
|
135 |
+
|
136 |
+
if "Error" in output_file:
|
137 |
+
st.error(output_file)
|
138 |
+
else:
|
139 |
+
st.success(f"Conversion Successful! Download the file:")
|
140 |
+
st.download_button(
|
141 |
+
label="Download Converted File",
|
142 |
+
data=open(output_file, 'rb').read(),
|
143 |
+
file_name=output_file
|
144 |
+
)
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
main()
|