Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
from tempfile import NamedTemporaryFile
|
5 |
+
|
6 |
+
# Paths
|
7 |
+
UPLOAD_DIR = '/content/uploads'
|
8 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
9 |
+
|
10 |
+
def save_uploaded_file(uploaded_file):
|
11 |
+
"""Save the uploaded file to the designated directory."""
|
12 |
+
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
13 |
+
with open(file_path, 'wb') as f:
|
14 |
+
f.write(uploaded_file.getbuffer())
|
15 |
+
return file_path
|
16 |
+
|
17 |
+
def run_ffmpeg_command(command):
|
18 |
+
"""Execute the FFmpeg command and return the output."""
|
19 |
+
try:
|
20 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
21 |
+
return result.stdout + '\n' + result.stderr
|
22 |
+
except Exception as e:
|
23 |
+
return str(e)
|
24 |
+
|
25 |
+
def main():
|
26 |
+
st.title('FFmpeg Web Interface')
|
27 |
+
|
28 |
+
# File upload
|
29 |
+
st.header('Upload File')
|
30 |
+
uploaded_file = st.file_uploader('Choose a file', type=['mp3', 'wav', 'mp4', 'avi'])
|
31 |
+
if uploaded_file:
|
32 |
+
file_path = save_uploaded_file(uploaded_file)
|
33 |
+
st.write(f'File saved to: {file_path}')
|
34 |
+
|
35 |
+
# Display uploaded file in audio or video player
|
36 |
+
file_type = uploaded_file.type
|
37 |
+
if file_type.startswith('audio/'):
|
38 |
+
st.audio(uploaded_file, format=file_type)
|
39 |
+
elif file_type.startswith('video/'):
|
40 |
+
st.video(uploaded_file, format=file_type)
|
41 |
+
|
42 |
+
# Command input
|
43 |
+
st.header('Command Input')
|
44 |
+
command = st.text_area('Enter FFmpeg commands here...')
|
45 |
+
if st.button('Execute Command'):
|
46 |
+
if command:
|
47 |
+
output = run_ffmpeg_command(command)
|
48 |
+
st.text_area('Logs', value=output, height=300)
|
49 |
+
else:
|
50 |
+
st.warning('Please enter a command.')
|
51 |
+
|
52 |
+
if __name__ == '__main__':
|
53 |
+
main()
|