Spaces:
Sleeping
Sleeping
File size: 944 Bytes
a755c90 45e5f54 a755c90 45e5f54 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import streamlit as st
import os
from moviepy.editor import VideoFileClip
def save_uploaded_file(uploaded_file):
try:
file_path = os.path.join('uploaded', uploaded_file.name)
with open(file_path, 'wb') as f:
f.write(uploaded_file.getvalue())
return file_path
except Exception as e:
st.error(f"Error: {e}")
return None
def encode_video_H264(video_path, remove_original=False):
"""
Encode video to H264 codec
Args:
video_path (str): path to video to be encoded
remove_original (bool): whether to remove original video after encoding
Returns:
output_path (str): path to encoded video
"""
output_path = video_path.split('.')[0] + '_H264.mp4'
clip = VideoFileClip(video_path)
clip.write_videofile(output_path, codec='libx264')
if remove_original:
os.remove(video_path)
clip.close()
return output_path |