File size: 1,860 Bytes
eefaa37
8df4907
00cb808
eefaa37
00cb808
 
 
 
 
4cf9976
00cb808
8df4907
eefaa37
00cb808
 
 
 
4cf9976
 
eefaa37
00cb808
 
8df4907
00cb808
 
 
 
 
 
 
 
8df4907
00cb808
 
 
 
 
 
8df4907
00cb808
 
 
 
 
 
 
8df4907
00cb808
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
import streamlit as st
import subprocess
import os

# 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)

# Streamlit UI
st.title('FFmpeg Command Executor')

# File upload
uploaded_file = st.file_uploader("Upload a file", type=['mp4', 'mkv', 'avi', 'mov'])
if uploaded_file:
    with open(os.path.join(UPLOAD_FOLDER, uploaded_file.name), 'wb') as f:
        f.write(uploaded_file.getbuffer())
    st.success('File uploaded successfully!')

# FFmpeg command input
ffmpeg_command = st.text_area("Enter FFmpeg command", placeholder="e.g., ffmpeg -i input.mp4 -vf scale=640:480 output.mp4")

if st.button('Run Command'):
    if not uploaded_file:
        st.error("Please upload a file before running the command.")
    elif not ffmpeg_command:
        st.error("Please enter an FFmpeg command.")
    else:
        # Run FFmpeg command
        command = ffmpeg_command.replace("input", os.path.join(UPLOAD_FOLDER, uploaded_file.name)).replace("output", os.path.join(PROCESSED_FOLDER, 'output.mp4'))
        try:
            result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
            st.success("Command executed successfully!")
            
            # Display logs
            st.subheader('FFmpeg Logs:')
            st.code(result.stdout)
            
            # Display video player
            video_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
            if os.path.exists(video_file):
                st.subheader('Processed Video:')
                st.video(video_file)
            else:
                st.warning("No video file found. Please check the command.")
        except subprocess.CalledProcessError as e:
            st.error(f"Error executing command: {e}")