Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
import ffmpeg
|
3 |
import os
|
4 |
import subprocess
|
|
|
5 |
|
6 |
# Directories for uploads and processing
|
7 |
UPLOAD_FOLDER = 'uploads'
|
@@ -9,16 +9,27 @@ PROCESSED_FOLDER = 'processed'
|
|
9 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
10 |
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Streamlit UI
|
13 |
st.title('FFmpeg Command Executor with ffmpeg-python')
|
14 |
|
15 |
# File upload
|
16 |
uploaded_file = st.file_uploader("Upload a file", type=None) # Accept any file type
|
17 |
if uploaded_file:
|
18 |
-
|
|
|
19 |
with open(file_path, 'wb') as f:
|
20 |
f.write(uploaded_file.getbuffer())
|
21 |
-
st.success('File uploaded successfully!')
|
22 |
|
23 |
# FFmpeg command input
|
24 |
ffmpeg_command = st.text_area("Enter FFmpeg command (e.g., -vf scale=640:480 output.mp4)", placeholder="e.g., -vf scale=640:480 output.mp4")
|
@@ -30,11 +41,10 @@ if st.button('Run Command'):
|
|
30 |
st.error("Please enter an FFmpeg command.")
|
31 |
else:
|
32 |
# Build paths
|
33 |
-
input_file = os.path.join(UPLOAD_FOLDER,
|
34 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
35 |
|
36 |
# Prepare FFmpeg command
|
37 |
-
# Ensure the output filename is correctly used
|
38 |
command = f"ffmpeg -i {input_file} {ffmpeg_command.replace('output', output_file)}"
|
39 |
|
40 |
try:
|
@@ -75,7 +85,7 @@ if st.button('Run ffmpeg-python Command'):
|
|
75 |
elif not ffmpeg_command:
|
76 |
st.error("Please enter an FFmpeg command.")
|
77 |
else:
|
78 |
-
input_file = os.path.join(UPLOAD_FOLDER,
|
79 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
80 |
|
81 |
# Define the command arguments
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
+
import ffmpeg
|
5 |
|
6 |
# Directories for uploads and processing
|
7 |
UPLOAD_FOLDER = 'uploads'
|
|
|
9 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
10 |
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
11 |
|
12 |
+
def get_new_filename(original_filename):
|
13 |
+
"""Generate a new filename with an incremented number."""
|
14 |
+
base, ext = os.path.splitext(original_filename)
|
15 |
+
i = 1
|
16 |
+
new_filename = f"{base}_{i}{ext}"
|
17 |
+
while os.path.exists(os.path.join(UPLOAD_FOLDER, new_filename)):
|
18 |
+
i += 1
|
19 |
+
new_filename = f"{base}_{i}{ext}"
|
20 |
+
return new_filename
|
21 |
+
|
22 |
# Streamlit UI
|
23 |
st.title('FFmpeg Command Executor with ffmpeg-python')
|
24 |
|
25 |
# File upload
|
26 |
uploaded_file = st.file_uploader("Upload a file", type=None) # Accept any file type
|
27 |
if uploaded_file:
|
28 |
+
new_filename = get_new_filename(uploaded_file.name)
|
29 |
+
file_path = os.path.join(UPLOAD_FOLDER, new_filename)
|
30 |
with open(file_path, 'wb') as f:
|
31 |
f.write(uploaded_file.getbuffer())
|
32 |
+
st.success(f'File uploaded successfully as {new_filename}!')
|
33 |
|
34 |
# FFmpeg command input
|
35 |
ffmpeg_command = st.text_area("Enter FFmpeg command (e.g., -vf scale=640:480 output.mp4)", placeholder="e.g., -vf scale=640:480 output.mp4")
|
|
|
41 |
st.error("Please enter an FFmpeg command.")
|
42 |
else:
|
43 |
# Build paths
|
44 |
+
input_file = os.path.join(UPLOAD_FOLDER, new_filename)
|
45 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
46 |
|
47 |
# Prepare FFmpeg command
|
|
|
48 |
command = f"ffmpeg -i {input_file} {ffmpeg_command.replace('output', output_file)}"
|
49 |
|
50 |
try:
|
|
|
85 |
elif not ffmpeg_command:
|
86 |
st.error("Please enter an FFmpeg command.")
|
87 |
else:
|
88 |
+
input_file = os.path.join(UPLOAD_FOLDER, new_filename)
|
89 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
90 |
|
91 |
# Define the command arguments
|