CoolFace
Apppublic

RabbitRUI/ruispace

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
videoio.py31 linesDownload Raw Back to utils
1import shutil2import uuid3 4import os5 6import cv27 8def load_video_to_cv2(input_path):9    video_stream = cv2.VideoCapture(input_path)10    fps = video_stream.get(cv2.CAP_PROP_FPS)11    full_frames = [] 12    while 1:13        still_reading, frame = video_stream.read()14        if not still_reading:15            video_stream.release()16            break 17        full_frames.append(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))18    return full_frames19 20def save_video_with_watermark(video, audio, save_path, watermark='docs/sadtalker_logo.png'):21    temp_file = str(uuid.uuid4())+'.mp4'22    cmd = r'ffmpeg -y -i "%s" -i "%s" -vcodec copy "%s"' % (video, audio, temp_file)23    os.system(cmd)24 25    if not watermark:26        shutil.move(temp_file, save_path)27    else:28        # watermark29        cmd = r'ffmpeg -y -hide_banner -i "%s" -i "%s" -filter_complex "[1]scale=100:-1[wm];[0][wm]overlay=(main_w-overlay_w)-10:10" "%s"' % (temp_file, watermark, save_path)30        os.system(cmd)31        os.remove(temp_file)