Théo Rousseaux commited on
Commit
45e5f54
1 Parent(s): cdb28da

convert H264

Browse files
Files changed (1) hide show
  1. utils.py +22 -1
utils.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import os
 
3
 
4
  def save_uploaded_file(uploaded_file):
5
  try:
@@ -9,4 +10,24 @@ def save_uploaded_file(uploaded_file):
9
  return file_path
10
  except Exception as e:
11
  st.error(f"Error: {e}")
12
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
+ from moviepy.editor import VideoFileClip
4
 
5
  def save_uploaded_file(uploaded_file):
6
  try:
 
10
  return file_path
11
  except Exception as e:
12
  st.error(f"Error: {e}")
13
+ return None
14
+
15
+ def encode_video_H264(video_path, remove_original=False):
16
+ """
17
+ Encode video to H264 codec
18
+
19
+ Args:
20
+ video_path (str): path to video to be encoded
21
+ remove_original (bool): whether to remove original video after encoding
22
+ Returns:
23
+ output_path (str): path to encoded video
24
+ """
25
+
26
+ output_path = video_path.split('.')[0] + '_H264.mp4'
27
+ clip = VideoFileClip(video_path)
28
+ clip.write_videofile(output_path, codec='libx264')
29
+ if remove_original:
30
+ os.remove(video_path)
31
+ clip.close()
32
+
33
+ return output_path