FFmpeg / app.py
RandomPersonRR's picture
Update app.py
8df4907 verified
raw
history blame
1.37 kB
import streamlit as st
import os
import subprocess
# Define directories for uploads and processed files
UPLOAD_DIR = 'uploads'
PROCESSED_DIR = 'processed'
# Create the directories if they don't exist
if not os.path.exists(UPLOAD_DIR):
os.makedirs(UPLOAD_DIR)
if not os.path.exists(PROCESSED_DIR):
os.makedirs(PROCESSED_DIR)
st.title('FFmpeg Command Executor')
# File uploader
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# Save the uploaded file
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
with open(file_path, 'wb') as f:
f.write(uploaded_file.getbuffer())
st.success('File uploaded successfully!')
# Input for ffmpeg command
command = st.text_area('Enter FFmpeg command', value=f'ffmpeg -i {file_path} -vf scale=1280:720 {os.path.join(PROCESSED_DIR, "output.mp4")}')
if st.button('Run Command'):
# Execute the FFmpeg command
try:
subprocess.run(command, shell=True, check=True)
st.success('Command executed successfully!')
# Display the processed video
output_file_path = os.path.join(PROCESSED_DIR, 'output.mp4')
st.video(output_file_path) # Display video in Streamlit
except subprocess.CalledProcessError as e:
st.error(f'Error executing command: {e}')