Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,48 @@
|
|
1 |
import streamlit as st
|
2 |
-
import os
|
3 |
import subprocess
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
if not os.path.exists(UPLOAD_DIR):
|
11 |
-
os.makedirs(UPLOAD_DIR)
|
12 |
-
if not os.path.exists(PROCESSED_DIR):
|
13 |
-
os.makedirs(PROCESSED_DIR)
|
14 |
|
|
|
15 |
st.title('FFmpeg Command Executor')
|
16 |
|
17 |
-
# File
|
18 |
-
uploaded_file = st.file_uploader("
|
19 |
-
|
20 |
-
|
21 |
-
# Save the uploaded file
|
22 |
-
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
23 |
-
with open(file_path, 'wb') as f:
|
24 |
f.write(uploaded_file.getbuffer())
|
25 |
st.success('File uploaded successfully!')
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
try:
|
33 |
-
subprocess.run(command, shell=True, check=True)
|
34 |
-
st.success(
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
# Display
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
except subprocess.CalledProcessError as e:
|
40 |
-
st.error(f
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import subprocess
|
3 |
+
import os
|
4 |
|
5 |
+
# Directories for uploads and processing
|
6 |
+
UPLOAD_FOLDER = 'uploads'
|
7 |
+
PROCESSED_FOLDER = 'processed'
|
8 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
9 |
+
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Streamlit UI
|
12 |
st.title('FFmpeg Command Executor')
|
13 |
|
14 |
+
# File upload
|
15 |
+
uploaded_file = st.file_uploader("Upload a file", type=['mp4', 'mkv', 'avi', 'mov'])
|
16 |
+
if uploaded_file:
|
17 |
+
with open(os.path.join(UPLOAD_FOLDER, uploaded_file.name), 'wb') as f:
|
|
|
|
|
|
|
18 |
f.write(uploaded_file.getbuffer())
|
19 |
st.success('File uploaded successfully!')
|
20 |
|
21 |
+
# FFmpeg command input
|
22 |
+
ffmpeg_command = st.text_area("Enter FFmpeg command", placeholder="e.g., ffmpeg -i input.mp4 -vf scale=640:480 output.mp4")
|
23 |
|
24 |
+
if st.button('Run Command'):
|
25 |
+
if not uploaded_file:
|
26 |
+
st.error("Please upload a file before running the command.")
|
27 |
+
elif not ffmpeg_command:
|
28 |
+
st.error("Please enter an FFmpeg command.")
|
29 |
+
else:
|
30 |
+
# Run FFmpeg command
|
31 |
+
command = ffmpeg_command.replace("input", os.path.join(UPLOAD_FOLDER, uploaded_file.name)).replace("output", os.path.join(PROCESSED_FOLDER, 'output.mp4'))
|
32 |
try:
|
33 |
+
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
34 |
+
st.success("Command executed successfully!")
|
35 |
+
|
36 |
+
# Display logs
|
37 |
+
st.subheader('FFmpeg Logs:')
|
38 |
+
st.code(result.stdout)
|
39 |
|
40 |
+
# Display video player
|
41 |
+
video_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
42 |
+
if os.path.exists(video_file):
|
43 |
+
st.subheader('Processed Video:')
|
44 |
+
st.video(video_file)
|
45 |
+
else:
|
46 |
+
st.warning("No video file found. Please check the command.")
|
47 |
except subprocess.CalledProcessError as e:
|
48 |
+
st.error(f"Error executing command: {e}")
|