Spaces:
Running
Running
File size: 2,382 Bytes
eefaa37 00cb808 172af62 322ee9c eefaa37 00cb808 4cf9976 322ee9c e6b42eb 00cb808 322ee9c eefaa37 322ee9c eefaa37 322ee9c 8df4907 322ee9c 172af62 322ee9c |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import streamlit as st
import os
import subprocess
import ffmpeg # Import the ffmpeg-python library
# Directories for uploads and processing
UPLOAD_FOLDER = 'uploads'
PROCESSED_FOLDER = 'processed'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(PROCESSED_FOLDER, exist_ok=True)
def save_uploaded_file(uploaded_file):
"""Save uploaded file to a designated folder without renaming it unless a file with the same name exists."""
file_path = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
# If a file with the same name already exists, generate a unique name
if os.path.exists(file_path):
base, ext = os.path.splitext(uploaded_file.name)
i = 1
while os.path.exists(os.path.join(UPLOAD_FOLDER, f"{base}_{i}{ext}")):
i += 1
file_path = os.path.join(UPLOAD_FOLDER, f"{base}_{i}{ext}")
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
return file_path
def run_ffmpeg(command):
"""Run the FFmpeg command and capture the output."""
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout, result.stderr
except Exception as e:
return "", str(e)
# Streamlit UI
st.title("FFmpeg Command Runner")
# File uploader
uploaded_file = st.file_uploader("Upload a file", type=None)
# Text area for FFmpeg commands
ffmpeg_command = st.text_area("Enter your FFmpeg command", "")
# Execute button
if st.button("Run FFmpeg Command"):
if uploaded_file:
# Save the uploaded file
uploaded_file_path = save_uploaded_file(uploaded_file)
st.write(f"File saved at: {uploaded_file_path}")
# Replace placeholder with the uploaded file path in the FFmpeg command
command_to_run = ffmpeg_command.replace("<input_file>", uploaded_file_path)
# Run the command
stdout, stderr = run_ffmpeg(command_to_run)
# Display the logs
st.text_area("FFmpeg Output", stdout)
st.text_area("FFmpeg Errors", stderr)
# Check for a successful FFmpeg process and show the video player if the output file exists
output_path = os.path.join(PROCESSED_FOLDER, "output.mp4") # Change as needed
if os.path.exists(output_path):
st.video(output_path)
else:
st.write("Please upload a file before running the command.") |