FitnessEquation / utils.py
Théo Rousseaux
convert H264
45e5f54
raw
history blame contribute delete
944 Bytes
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