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