RandomPersonRR commited on
Commit
00cb808
·
verified ·
1 Parent(s): c950606

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -27
app.py CHANGED
@@ -1,40 +1,48 @@
1
  import streamlit as st
2
- import os
3
  import subprocess
 
4
 
5
- # Define directories for uploads and processed files
6
- UPLOAD_DIR = 'uploads'
7
- PROCESSED_DIR = 'processed'
8
-
9
- # Create the directories if they don't exist
10
- if not os.path.exists(UPLOAD_DIR):
11
- os.makedirs(UPLOAD_DIR)
12
- if not os.path.exists(PROCESSED_DIR):
13
- os.makedirs(PROCESSED_DIR)
14
 
 
15
  st.title('FFmpeg Command Executor')
16
 
17
- # File uploader
18
- uploaded_file = st.file_uploader("Choose a file")
19
-
20
- if uploaded_file is not None:
21
- # Save the uploaded file
22
- file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
23
- with open(file_path, 'wb') as f:
24
  f.write(uploaded_file.getbuffer())
25
  st.success('File uploaded successfully!')
26
 
27
- # Input for ffmpeg command
28
- command = st.text_area('Enter FFmpeg command', value=f'ffmpeg -i {file_path} -vf scale=1280:720 {os.path.join(PROCESSED_DIR, "output.mp4")}')
29
 
30
- if st.button('Run Command'):
31
- # Execute the FFmpeg command
 
 
 
 
 
 
32
  try:
33
- subprocess.run(command, shell=True, check=True)
34
- st.success('Command executed successfully!')
 
 
 
 
35
 
36
- # Display the processed video
37
- output_file_path = os.path.join(PROCESSED_DIR, 'output.mp4')
38
- st.video(output_file_path) # Display video in Streamlit
 
 
 
 
39
  except subprocess.CalledProcessError as e:
40
- st.error(f'Error executing command: {e}')
 
1
  import streamlit as st
 
2
  import subprocess
3
+ import os
4
 
5
+ # Directories for uploads and processing
6
+ UPLOAD_FOLDER = 'uploads'
7
+ PROCESSED_FOLDER = 'processed'
8
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
9
+ os.makedirs(PROCESSED_FOLDER, exist_ok=True)
 
 
 
 
10
 
11
+ # Streamlit UI
12
  st.title('FFmpeg Command Executor')
13
 
14
+ # File upload
15
+ uploaded_file = st.file_uploader("Upload a file", type=['mp4', 'mkv', 'avi', 'mov'])
16
+ if uploaded_file:
17
+ with open(os.path.join(UPLOAD_FOLDER, uploaded_file.name), 'wb') as f:
 
 
 
18
  f.write(uploaded_file.getbuffer())
19
  st.success('File uploaded successfully!')
20
 
21
+ # FFmpeg command input
22
+ ffmpeg_command = st.text_area("Enter FFmpeg command", placeholder="e.g., ffmpeg -i input.mp4 -vf scale=640:480 output.mp4")
23
 
24
+ if st.button('Run Command'):
25
+ if not uploaded_file:
26
+ st.error("Please upload a file before running the command.")
27
+ elif not ffmpeg_command:
28
+ st.error("Please enter an FFmpeg command.")
29
+ else:
30
+ # Run FFmpeg command
31
+ command = ffmpeg_command.replace("input", os.path.join(UPLOAD_FOLDER, uploaded_file.name)).replace("output", os.path.join(PROCESSED_FOLDER, 'output.mp4'))
32
  try:
33
+ result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
34
+ st.success("Command executed successfully!")
35
+
36
+ # Display logs
37
+ st.subheader('FFmpeg Logs:')
38
+ st.code(result.stdout)
39
 
40
+ # Display video player
41
+ video_file = os.path.join(PROCESSED_FOLDER, 'output.mp4')
42
+ if os.path.exists(video_file):
43
+ st.subheader('Processed Video:')
44
+ st.video(video_file)
45
+ else:
46
+ st.warning("No video file found. Please check the command.")
47
  except subprocess.CalledProcessError as e:
48
+ st.error(f"Error executing command: {e}")