mishiawan commited on
Commit
19b03aa
·
verified ·
1 Parent(s): 5cbd151

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
4
- from moviepy.editor import VideoFileClip
5
  from PIL import Image
6
- import io
 
 
 
7
 
8
  # Function to apply filters
9
  def apply_filter(frame, filter_name):
@@ -15,7 +17,10 @@ def apply_filter(frame, filter_name):
15
  return cv2.convertScaleAbs(frame, alpha=1.5, beta=0)
16
  elif filter_name == 'Contrast':
17
  return cv2.convertScaleAbs(frame, alpha=2, beta=0)
18
- # More filters can be added here
 
 
 
19
  else:
20
  return frame
21
 
@@ -27,23 +32,32 @@ st.write("Upload a video and apply filters")
27
  video_file = st.file_uploader("Upload your video", type=["mp4", "avi", "mov"])
28
 
29
  if video_file:
30
- # Load the video
31
  st.video(video_file)
32
 
33
  # Select filter
34
  filter_choice = st.selectbox("Select a filter", ["None", "Grayscale", "Blur", "Sharpness", "Contrast", "Saturation"])
35
 
36
- # Process the video
37
  if st.button("Apply Filter and Download"):
38
- video_clip = VideoFileClip(video_file)
39
- temp_output = "output_video.mp4"
 
 
 
 
40
 
 
41
  def process_frame(frame):
42
  return apply_filter(frame, filter_choice)
43
-
44
  processed_video = video_clip.fl_image(process_frame)
45
- processed_video.write_videofile(temp_output)
46
-
 
 
 
 
47
  # Provide download link
48
- with open(temp_output, "rb") as f:
49
  st.download_button("Download edited video", f, file_name="edited_video.mp4")
 
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
 
4
  from PIL import Image
5
+ import tempfile
6
+ import os
7
+ from moviepy.editor import VideoFileClip
8
+ from moviepy.editor import vfx
9
 
10
  # Function to apply filters
11
  def apply_filter(frame, filter_name):
 
17
  return cv2.convertScaleAbs(frame, alpha=1.5, beta=0)
18
  elif filter_name == 'Contrast':
19
  return cv2.convertScaleAbs(frame, alpha=2, beta=0)
20
+ elif filter_name == 'Saturation':
21
+ hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
22
+ hsv[...,1] = hsv[...,1] * 1.5 # increase saturation
23
+ return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
24
  else:
25
  return frame
26
 
 
32
  video_file = st.file_uploader("Upload your video", type=["mp4", "avi", "mov"])
33
 
34
  if video_file:
35
+ # Display the uploaded video
36
  st.video(video_file)
37
 
38
  # Select filter
39
  filter_choice = st.selectbox("Select a filter", ["None", "Grayscale", "Blur", "Sharpness", "Contrast", "Saturation"])
40
 
41
+ # Process the video and apply filter
42
  if st.button("Apply Filter and Download"):
43
+ # Temporary file to store the video
44
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
45
+ tmp_file.write(video_file.read())
46
+ video_path = tmp_file.name
47
+
48
+ video_clip = VideoFileClip(video_path)
49
 
50
+ # Apply filter to video
51
  def process_frame(frame):
52
  return apply_filter(frame, filter_choice)
53
+
54
  processed_video = video_clip.fl_image(process_frame)
55
+
56
+ # Saving the output video
57
+ output_path = os.path.join("output", "edited_video.mp4")
58
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
59
+ processed_video.write_videofile(output_path)
60
+
61
  # Provide download link
62
+ with open(output_path, "rb") as f:
63
  st.download_button("Download edited video", f, file_name="edited_video.mp4")