Spaces:
Running
Running
Update 01_📼_Upload_Video_File.py
Browse files- 01_📼_Upload_Video_File.py +10 -4
01_📼_Upload_Video_File.py
CHANGED
@@ -48,7 +48,12 @@ def main():
|
|
48 |
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
49 |
temp_file.write(uploaded_file.read())
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Open the video using cv2.VideoCapture
|
54 |
video = cv2.VideoCapture(temp_file.name)
|
@@ -111,9 +116,10 @@ def main():
|
|
111 |
# Convert the output video to a format compatible with Streamlit
|
112 |
converted_filename = "converted_output.mp4"
|
113 |
clip = mp.VideoFileClip(output_filename)
|
114 |
-
clip = clip.set_audio(audio)
|
115 |
|
116 |
-
|
|
|
|
|
117 |
clip.write_videofile(converted_filename)
|
118 |
|
119 |
# Display the converted video using st.video()
|
@@ -139,4 +145,4 @@ if __name__ == "__main__":
|
|
139 |
"image link](https://i.imgur.com/thJhzOO.png)](https://www.buymeacoffee.com/clementdelteil)")
|
140 |
st.markdown(
|
141 |
"###### [Blog post of the project](https://medium.com/geekculture/creating-a-web-app-to-colorize-images-and-youtube-videos-80f5be2d0f68)"
|
142 |
-
)
|
|
|
48 |
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
49 |
temp_file.write(uploaded_file.read())
|
50 |
|
51 |
+
# Check if the video has audio
|
52 |
+
try:
|
53 |
+
audio = mp.AudioFileClip(temp_file.name)
|
54 |
+
except Exception as e:
|
55 |
+
audio = None
|
56 |
+
st.warning("No audio found in the video. Proceeding without audio.")
|
57 |
|
58 |
# Open the video using cv2.VideoCapture
|
59 |
video = cv2.VideoCapture(temp_file.name)
|
|
|
116 |
# Convert the output video to a format compatible with Streamlit
|
117 |
converted_filename = "converted_output.mp4"
|
118 |
clip = mp.VideoFileClip(output_filename)
|
|
|
119 |
|
120 |
+
if audio is not None:
|
121 |
+
clip = clip.set_audio(audio)
|
122 |
+
|
123 |
clip.write_videofile(converted_filename)
|
124 |
|
125 |
# Display the converted video using st.video()
|
|
|
145 |
"image link](https://i.imgur.com/thJhzOO.png)](https://www.buymeacoffee.com/clementdelteil)")
|
146 |
st.markdown(
|
147 |
"###### [Blog post of the project](https://medium.com/geekculture/creating-a-web-app-to-colorize-images-and-youtube-videos-80f5be2d0f68)"
|
148 |
+
)
|