167AliRaza commited on
Commit
b466991
·
verified ·
1 Parent(s): a804d89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
 
6
  st.set_page_config(page_title="Video Speed & Compression Tool", layout="centered")
7
 
8
- st.title("🎬 Video Speed & Compression Tool (Fast FFmpeg)")
9
 
10
  uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])
11
 
@@ -22,19 +22,15 @@ if uploaded_file is not None:
22
 
23
  if st.button("Process Video"):
24
  with st.spinner("Processing... Please wait"):
25
- # Save uploaded video to temp file
26
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_input:
27
  tmp_input.write(uploaded_file.read())
28
  input_path = tmp_input.name
29
 
30
- # Output path
31
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
32
 
33
- # Calculate ffmpeg speed filters
34
- video_speed = 1 / speed # setpts works with inverse of speed
35
- audio_speed = speed # atempo works with speed directly
36
 
37
- # Build ffmpeg command
38
  if compress:
39
  # Re-encode with compression
40
  cmd = [
@@ -45,12 +41,12 @@ if uploaded_file is not None:
45
  "-y", output_path
46
  ]
47
  else:
48
- # Change speed but keep original quality
49
  cmd = [
50
  "ffmpeg", "-i", input_path,
51
  "-filter_complex", f"[0:v]setpts={video_speed}*PTS[v];[0:a]atempo={audio_speed}[a]",
52
  "-map", "[v]", "-map", "[a]",
53
- "-c:v", "libx264", "-crf", "18", "-preset", "fast", # near-lossless
54
  "-y", output_path
55
  ]
56
 
@@ -58,10 +54,8 @@ if uploaded_file is not None:
58
 
59
  st.success("✅ Processing complete!")
60
 
61
- # Show processed video
62
  st.video(output_path)
63
 
64
- # Download button
65
  with open(output_path, "rb") as f:
66
  st.download_button(
67
  label="Download Processed Video",
@@ -70,6 +64,5 @@ if uploaded_file is not None:
70
  mime="video/mp4"
71
  )
72
 
73
- # Cleanup
74
  os.remove(input_path)
75
  os.remove(output_path)
 
5
 
6
  st.set_page_config(page_title="Video Speed & Compression Tool", layout="centered")
7
 
8
+ st.title("🎬 Video Speed & Compression Tool (Ultra Fast Lossless Mode)")
9
 
10
  uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "mov", "avi", "mkv"])
11
 
 
22
 
23
  if st.button("Process Video"):
24
  with st.spinner("Processing... Please wait"):
 
25
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_input:
26
  tmp_input.write(uploaded_file.read())
27
  input_path = tmp_input.name
28
 
 
29
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
30
 
31
+ video_speed = 1 / speed
32
+ audio_speed = speed
 
33
 
 
34
  if compress:
35
  # Re-encode with compression
36
  cmd = [
 
41
  "-y", output_path
42
  ]
43
  else:
44
+ # Lossless mode (copy original codec without full re-encode)
45
  cmd = [
46
  "ffmpeg", "-i", input_path,
47
  "-filter_complex", f"[0:v]setpts={video_speed}*PTS[v];[0:a]atempo={audio_speed}[a]",
48
  "-map", "[v]", "-map", "[a]",
49
+ "-c:v", "copy", "-c:a", "aac", "-b:a", "192k", # copy video, re-encode only audio for sync
50
  "-y", output_path
51
  ]
52
 
 
54
 
55
  st.success("✅ Processing complete!")
56
 
 
57
  st.video(output_path)
58
 
 
59
  with open(output_path, "rb") as f:
60
  st.download_button(
61
  label="Download Processed Video",
 
64
  mime="video/mp4"
65
  )
66
 
 
67
  os.remove(input_path)
68
  os.remove(output_path)