File size: 3,292 Bytes
eefaa37
172af62
00cb808
172af62
eefaa37
00cb808
 
 
 
 
4cf9976
00cb808
172af62
eefaa37
00cb808
172af62
00cb808
172af62
 
4cf9976
 
eefaa37
00cb808
172af62
8df4907
00cb808
 
 
 
 
 
172af62
 
 
 
 
 
 
 
8df4907
172af62
00cb808
 
 
 
 
 
8df4907
00cb808
172af62
00cb808
172af62
00cb808
 
8df4907
172af62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import streamlit as st
import ffmpeg
import os
import subprocess

# 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 with ffmpeg-python')

# File upload
uploaded_file = st.file_uploader("Upload a file", type=None)  # Accept any file type
if uploaded_file:
    file_path = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
    with open(file_path, 'wb') as f:
        f.write(uploaded_file.getbuffer())
    st.success('File uploaded successfully!')

# FFmpeg command input
ffmpeg_command = st.text_area("Enter FFmpeg command (e.g., -vf scale=640:480 output.mp4)", placeholder="e.g., -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:
        # Build paths
        input_file = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
        output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')

        # Prepare FFmpeg command
        # Ensure the output filename is correctly used
        command = f"ffmpeg -i {input_file} {ffmpeg_command.replace('output', output_file)}"

        try:
            # Execute FFmpeg command
            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
            if os.path.exists(output_file):
                st.subheader('Processed Video:')
                st.video(output_file)
            else:
                st.warning("No video file found. Please check the command.")
        except subprocess.CalledProcessError as e:
            st.error(f"Error executing command: {e}")

# Using ffmpeg-python to run commands directly
def run_ffmpeg_command(input_path, output_path, command_args):
    try:
        # ffmpeg-python command execution
        ffmpeg.input(input_path).output(output_path, **command_args).run(overwrite_output=True)
        st.success("Command executed successfully with ffmpeg-python!")
        
        # Display processed video
        st.subheader('Processed Video:')
        st.video(output_path)
    except ffmpeg.Error as e:
        st.error(f"Error executing command with ffmpeg-python: {e}")

# Example usage of ffmpeg-python
if st.button('Run ffmpeg-python 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:
        input_file = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
        output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
        
        # Define the command arguments
        # Convert ffmpeg_command into a dictionary format suitable for ffmpeg-python
        command_args = {}  # You need to parse the `ffmpeg_command` into this dictionary
        
        run_ffmpeg_command(input_file, output_file, command_args)