Spaces:
Running
Running
RandomPersonRR
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ if uploaded_file:
|
|
32 |
st.success(f'File uploaded successfully as {new_filename}!')
|
33 |
|
34 |
# FFmpeg command input
|
35 |
-
ffmpeg_command = st.text_area("Enter FFmpeg command
|
36 |
|
37 |
if st.button('Run Command'):
|
38 |
if not uploaded_file:
|
@@ -43,9 +43,12 @@ if st.button('Run Command'):
|
|
43 |
# Build paths
|
44 |
input_file = os.path.join(UPLOAD_FOLDER, new_filename)
|
45 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
46 |
-
|
47 |
# Prepare FFmpeg command
|
48 |
-
command = f"ffmpeg -i {input_file} {ffmpeg_command
|
|
|
|
|
|
|
49 |
|
50 |
try:
|
51 |
# Execute FFmpeg command
|
@@ -63,33 +66,4 @@ if st.button('Run Command'):
|
|
63 |
else:
|
64 |
st.warning("No video file found. Please check the command.")
|
65 |
except subprocess.CalledProcessError as e:
|
66 |
-
st.error(f"Error executing command: {e}")
|
67 |
-
|
68 |
-
# Using ffmpeg-python to run commands directly
|
69 |
-
def run_ffmpeg_command(input_path, output_path, command_args):
|
70 |
-
try:
|
71 |
-
# ffmpeg-python command execution
|
72 |
-
ffmpeg.input(input_path).output(output_path, **command_args).run(overwrite_output=True)
|
73 |
-
st.success("Command executed successfully with ffmpeg-python!")
|
74 |
-
|
75 |
-
# Display processed video
|
76 |
-
st.subheader('Processed Video:')
|
77 |
-
st.video(output_path)
|
78 |
-
except ffmpeg.Error as e:
|
79 |
-
st.error(f"Error executing command with ffmpeg-python: {e}")
|
80 |
-
|
81 |
-
# Example usage of ffmpeg-python
|
82 |
-
if st.button('Run ffmpeg-python Command'):
|
83 |
-
if not uploaded_file:
|
84 |
-
st.error("Please upload a file before running the command.")
|
85 |
-
elif not ffmpeg_command:
|
86 |
-
st.error("Please enter an FFmpeg command.")
|
87 |
-
else:
|
88 |
-
input_file = os.path.join(UPLOAD_FOLDER, new_filename)
|
89 |
-
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
90 |
-
|
91 |
-
# Define the command arguments
|
92 |
-
# Convert ffmpeg_command into a dictionary format suitable for ffmpeg-python
|
93 |
-
command_args = {} # You need to parse the `ffmpeg_command` into this dictionary
|
94 |
-
|
95 |
-
run_ffmpeg_command(input_file, output_file, command_args)
|
|
|
32 |
st.success(f'File uploaded successfully as {new_filename}!')
|
33 |
|
34 |
# FFmpeg command input
|
35 |
+
ffmpeg_command = st.text_area("Enter FFmpeg command", placeholder="e.g., -vf scale=640:480 output.mp4")
|
36 |
|
37 |
if st.button('Run Command'):
|
38 |
if not uploaded_file:
|
|
|
43 |
# Build paths
|
44 |
input_file = os.path.join(UPLOAD_FOLDER, new_filename)
|
45 |
output_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
|
46 |
+
|
47 |
# Prepare FFmpeg command
|
48 |
+
command = f"ffmpeg -i {input_file} {ffmpeg_command}"
|
49 |
+
|
50 |
+
# Replace 'output' placeholder in the command with the actual output file path
|
51 |
+
command = command.replace('output', output_file)
|
52 |
|
53 |
try:
|
54 |
# Execute FFmpeg command
|
|
|
66 |
else:
|
67 |
st.warning("No video file found. Please check the command.")
|
68 |
except subprocess.CalledProcessError as e:
|
69 |
+
st.error(f"Error executing command: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|