|
import shutil
|
|
import uuid
|
|
|
|
import os
|
|
|
|
import cv2
|
|
|
|
def load_video_to_cv2(input_path):
|
|
video_stream = cv2.VideoCapture(input_path)
|
|
fps = video_stream.get(cv2.CAP_PROP_FPS)
|
|
full_frames = []
|
|
while 1:
|
|
still_reading, frame = video_stream.read()
|
|
if not still_reading:
|
|
video_stream.release()
|
|
break
|
|
full_frames.append(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
|
return full_frames
|
|
|
|
def save_video_with_watermark(video, audio, save_path, watermark=False):
|
|
temp_file = str(uuid.uuid4())+'.mp4'
|
|
from moviepy.editor import VideoFileClip, AudioFileClip
|
|
import tempfile
|
|
import base64
|
|
|
|
|
|
audio_clip = AudioFileClip(audio)
|
|
video_clip = VideoFileClip(video)
|
|
|
|
final_clip = video_clip.set_audio(audio_clip)
|
|
|
|
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
|
temp_file.close()
|
|
temp_file_path = temp_file.name
|
|
final_clip.write_videofile(temp_file_path)
|
|
|
|
with open(temp_file_path, 'rb') as f:
|
|
video_content = f.read()
|
|
|
|
base64_video = base64.b64encode(video_content).decode('utf-8')
|
|
|
|
return base64_video, temp_file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|