167AliRaza commited on
Commit
329ed22
·
verified ·
1 Parent(s): 1903c80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -15
app.py CHANGED
@@ -4,15 +4,41 @@ import subprocess
4
  import os
5
  import re
6
 
7
- st.set_page_config(page_title="Video Speed & Compression Tool", layout="centered")
8
-
9
- st.title("🎬 Video Speed & Compression Tool (Custom Speed + Always Compress)")
10
-
11
- uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])
12
-
13
- # Let user choose any custom speed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  speed = st.number_input(
15
- "Set Playback Speed (e.g., 1.2 for 20% faster, 0.5 for half speed)",
16
  min_value=0.25,
17
  max_value=4.0,
18
  value=1.5,
@@ -22,7 +48,8 @@ speed = st.number_input(
22
  if uploaded_file is not None:
23
  st.video(uploaded_file)
24
 
25
- if st.button("Process Video"):
 
26
  with st.spinner("Processing... Please wait"):
27
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_input:
28
  tmp_input.write(uploaded_file.read())
@@ -43,11 +70,11 @@ if uploaded_file is not None:
43
  "-y", output_path
44
  ]
45
 
46
- # Progress bar setup
47
  progress_text = st.empty()
48
  progress_bar = st.progress(0)
49
 
50
- # Get video duration first
51
  probe = subprocess.run(
52
  ["ffprobe", "-v", "error", "-show_entries", "format=duration",
53
  "-of", "default=noprint_wrappers=1:nokey=1", input_path],
@@ -58,12 +85,11 @@ if uploaded_file is not None:
58
  except:
59
  total_duration = None
60
 
61
- # Run ffmpeg with live output parsing
62
  process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
63
 
64
  for line in process.stdout:
65
  if "time=" in line and total_duration:
66
- # Extract current time processed
67
  match = re.search(r"time=(\d+:\d+:\d+\.\d+)", line)
68
  if match:
69
  h, m, s = match.group(1).split(":")
@@ -79,10 +105,22 @@ if uploaded_file is not None:
79
  # Show processed video
80
  st.video(output_path)
81
 
82
- # Download button
 
 
 
 
 
 
 
 
 
 
 
 
83
  with open(output_path, "rb") as f:
84
  st.download_button(
85
- label="Download Processed Video",
86
  data=f,
87
  file_name="processed_video.mp4",
88
  mime="video/mp4"
 
4
  import os
5
  import re
6
 
7
+ # Page settings for mobile
8
+ st.set_page_config(page_title="Video Speed Tool", layout="centered")
9
+
10
+ # CSS for mobile-friendly design
11
+ st.markdown("""
12
+ <style>
13
+ /* Center title and make it concise */
14
+ .title-center {
15
+ text-align: center;
16
+ font-size: 1.8em;
17
+ font-weight: bold;
18
+ }
19
+ /* Bold button text */
20
+ div.stButton > button {
21
+ font-weight: bold;
22
+ width: 100%;
23
+ border-radius: 8px;
24
+ padding: 10px 0;
25
+ font-size: 1.1em;
26
+ }
27
+ /* Center elements */
28
+ .block-container {
29
+ padding-top: 1rem;
30
+ padding-bottom: 1rem;
31
+ }
32
+ </style>
33
+ """, unsafe_allow_html=True)
34
+
35
+ st.markdown('<p class="title-center">🎬 Video Speed Tool</p>', unsafe_allow_html=True)
36
+
37
+ uploaded_file = st.file_uploader("Upload video", type=["mp4", "mov", "avi", "mkv"])
38
+
39
+ # Speed input
40
  speed = st.number_input(
41
+ "Speed (0.25x - 4x)",
42
  min_value=0.25,
43
  max_value=4.0,
44
  value=1.5,
 
48
  if uploaded_file is not None:
49
  st.video(uploaded_file)
50
 
51
+ # Center button
52
+ if st.button("PROCESS VIDEO"):
53
  with st.spinner("Processing... Please wait"):
54
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_input:
55
  tmp_input.write(uploaded_file.read())
 
70
  "-y", output_path
71
  ]
72
 
73
+ # Progress bar
74
  progress_text = st.empty()
75
  progress_bar = st.progress(0)
76
 
77
+ # Get video duration
78
  probe = subprocess.run(
79
  ["ffprobe", "-v", "error", "-show_entries", "format=duration",
80
  "-of", "default=noprint_wrappers=1:nokey=1", input_path],
 
85
  except:
86
  total_duration = None
87
 
88
+ # Run ffmpeg with live progress
89
  process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
90
 
91
  for line in process.stdout:
92
  if "time=" in line and total_duration:
 
93
  match = re.search(r"time=(\d+:\d+:\d+\.\d+)", line)
94
  if match:
95
  h, m, s = match.group(1).split(":")
 
105
  # Show processed video
106
  st.video(output_path)
107
 
108
+ # Bold download button
109
+ st.markdown("""
110
+ <style>
111
+ .stDownloadButton button {
112
+ font-weight: bold;
113
+ width: 100%;
114
+ border-radius: 8px;
115
+ padding: 10px 0;
116
+ font-size: 1.1em;
117
+ }
118
+ </style>
119
+ """, unsafe_allow_html=True)
120
+
121
  with open(output_path, "rb") as f:
122
  st.download_button(
123
+ label="DOWNLOAD VIDEO",
124
  data=f,
125
  file_name="processed_video.mp4",
126
  mime="video/mp4"