Files
audio2motion/scripts/Test/frames-to-video-2.py

111 lines
4.3 KiB
Python

import moviepy
import numpy as np
from pathlib import Path
from moviepy.editor import *
STEP_VIDEO = False
STEP_CONCATE = True
if __name__ == "__main__":
video_name = "2021-P09"
path_root = Path(f"/yrfs/lsen/DATA/LuoXData/processing2/{video_name}")
path_frame = path_root.joinpath(f"frames")
path_audio = path_root.joinpath("audio/audio_trim.wav")
# load audio
clip_audio = AudioFileClip(str(path_audio))
clip_audio.set_duration(120.0)
# load video
clip_video = ImageSequenceClip(path_frame, fps=50, load_images=True)
clip_video.set_duration(120.0)
# add audio
clip_image.write_videofile(str(path_image_save), fps=25)
concate_clips = concate_clips.set_audio(clip_audio)
# save
path_concate_save = path_data.joinpath("concate4.mp4")
#concate_clips = concate_clips.resize(width=720)
concate_clips.write_videofile(str(path_concate_save), fps=25)
# # to video
# if STEP_VIDEO:
# path_image = path_data.joinpath("frames_crop")
# path_image_save = path_data.joinpath("images.mp4")
# clip_image = ImageSequenceClip(path_image, fps=25, load_images=True)
# clip_image.write_videofile(str(path_image_save), fps=25)
# path_frame = path_data.joinpath("render")
# path_frame_save = path_data.joinpath("render.mp4")
# clip_render = ImageSequenceClip(path_frame, fps=25, load_images=True)
# clip_render.write_videofile(str(path_frame_save), fps=25)
# path_frame = path_data.joinpath("render_pt")
# path_frame_save = path_data.joinpath("render_pt.mp4")
# clip_render_pt = ImageSequenceClip(path_frame, fps=25, load_images=True)
# clip_render_pt.write_videofile(str(path_frame_save), fps=25)
# path_frame = path_data.joinpath("render_pt_fix_idn")
# path_frame_save = path_data.joinpath("render_pt_fix_idn.mp4")
# clip_render_pt2 = ImageSequenceClip(path_frame, fps=25, load_images=True)
# clip_render_pt2.write_videofile(str(path_frame_save), fps=25)
# # concate
# if STEP_CONCATE:
# # image
# clip_image = VideoFileClip(str(path_data.joinpath("images.mp4"))).margin(10)
# clip_text = TextClip("Crop Image", fontsize = 14, color = 'white', stroke_width=3)
# clip_text = clip_text.set_pos((0.4, 0.9), relative=True).set_duration(clip_image.duration)
# clip_image = CompositeVideoClip([clip_image, clip_text])
# # render
# clip_render = VideoFileClip(str(path_data.joinpath("render.mp4"))).margin(10)
# clip_text = TextClip("Render GT", fontsize = 14, color = 'white', stroke_width=3)
# clip_text = clip_text.set_pos((0.4,0.9), relative=True).set_duration(clip_render.duration)
# clip_render = CompositeVideoClip([clip_render, clip_text])
# # render with specific identiy
# clip_render2 = VideoFileClip(str(path_data.joinpath("render_pt.mp4"))).margin(10)
# clip_text = TextClip("Render PT fix identity", fontsize = 14, color = 'white', stroke_width=3)
# clip_text = clip_text.set_pos((0.2,0.9), relative=True).set_duration(clip_render2.duration)
# clip_render2 = CompositeVideoClip([clip_render2, clip_text])
# # render with specific identiy
# clip_render3 = VideoFileClip(str(path_data.joinpath("render_pt_fix_idn.mp4"))).margin(10)
# # clip_text = TextClip("Render PT with fixed identity", fontsize = 14, color = 'red')
# # clip_text = clip_text.set_pos("center", "top").set_duration(clip_render3.duration)
# # clip_render3 = CompositeVideoClip([clip_render3, clip_text])
# # audio
# path_audio = path_data.joinpath("../audio/test_video.wav")
# clip_audio = AudioFileClip(str(path_audio))
# # concate
# # concate_clips = clips_array([[clip_image, clip_render],
# # [clip_render2, clip_render3]])
# concate_clips = clips_array([[clip_image, clip_render, clip_render2]])
# concate_clips = concate_clips.set_audio(clip_audio)
# # save
# path_concate_save = path_data.joinpath("concate4.mp4")
# #concate_clips = concate_clips.resize(width=720)
# concate_clips.write_videofile(str(path_concate_save), fps=25)