Spaces:
Sleeping
Sleeping
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() |