start adding intro framework
This commit is contained in:
parent
b49b05c4d3
commit
1d6e0ce290
50
main.py
50
main.py
@ -38,6 +38,22 @@ def main(args):
|
||||
sys.exit(-1)
|
||||
log.info("preparing video", input_video=input_file)
|
||||
|
||||
intro_file = args.introvidpath
|
||||
if intro_file is not None:
|
||||
intro_vid_path = Path(intro_file)
|
||||
if not in_vid_path.is_file():
|
||||
log.error("the specified input path does not exist for the intro", path=intro_file)
|
||||
sys.exit(-1)
|
||||
log.info("found intro", input_video=intro_file)
|
||||
|
||||
outro_file = args.outrovidpath
|
||||
if outro_file is not None:
|
||||
outro_vid_path = Path(outro_file)
|
||||
if not outro_vid_path.is_file():
|
||||
log.error("the specified input path does not exist for the outro", path=outro_file)
|
||||
sys.exit(-1)
|
||||
log.info("found outro", input_video=outro_file)
|
||||
|
||||
# Hash the video, we use this to see if we have processed this video before
|
||||
# and as a simple way to generate temp file names
|
||||
sha1 = hashlib.sha1()
|
||||
@ -135,7 +151,7 @@ def main(args):
|
||||
out_path = Path(args.destination)
|
||||
log.info("rendering...")
|
||||
start = time.time()
|
||||
render_moments(moment_results[index_min][0], str(in_vid_path.resolve()), str(out_path.resolve()))
|
||||
render_moments(moment_results[index_min][0], str(in_vid_path.resolve()), str(out_path.resolve()), intro_path=intro_file, parallelism=args.parallelism)
|
||||
log.info("render complete", duration=time.time() - start, output=str(out_path.resolve()))
|
||||
sys.exit(0)
|
||||
iterations = iterations + parallelism
|
||||
@ -183,19 +199,47 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--cost-function", dest="cost", choices=ERROR_FUNCS.keys(), default='quadratic')
|
||||
|
||||
parser.add_argument(
|
||||
"--minduration",
|
||||
"--min-duration",
|
||||
default=8,
|
||||
help="Minimum clip duration",
|
||||
dest="mindur",
|
||||
type=int,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--maxduration",
|
||||
"--max-duration",
|
||||
default=15,
|
||||
help="Maximum clip duration",
|
||||
dest="maxdur",
|
||||
type=int,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--intro-video",
|
||||
default=None,
|
||||
help="Path to a video file to use as an intro",
|
||||
dest="introvidpath",
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--outro-video",
|
||||
default=None,
|
||||
help="Path to a video file to use as an outro",
|
||||
dest="outrovidpath",
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--title-slide-text",
|
||||
default=None,
|
||||
help="Text to show during a title slide. The title slide is played after any provided intro. If there is no intro, the title slide is the intro",
|
||||
dest="outrovidpath",
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--title-slide-duration",
|
||||
default=5,
|
||||
help="Time, in seconds, to show a title slide for",
|
||||
dest="outrovidpath",
|
||||
type=str,
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
|
@ -1,4 +1,5 @@
|
||||
import moviepy.editor as mp
|
||||
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
||||
|
||||
def get_subclips(source_video_path, moments):
|
||||
vid = mp.VideoFileClip(source_video_path)
|
||||
@ -7,10 +8,15 @@ def get_subclips(source_video_path, moments):
|
||||
clips.append(vid.subclip(m.start, m.stop))
|
||||
return clips, vid
|
||||
|
||||
def render_moments(moments, input_video_path, output_path):
|
||||
def render_moments(moments, input_video_path, output_path, intro_path=None, outro_path=None, parallelism=1):
|
||||
clips, vid = get_subclips(input_video_path, moments)
|
||||
to_render = mp.concatenate_videoclips(clips)
|
||||
to_render.write_videofile(output_path, logger=None)
|
||||
size = clips[0].size
|
||||
if intro_path is not None:
|
||||
iclip = mp.VideoFileClip(intro_path)
|
||||
clips.insert(0, iclip)
|
||||
composite = CompositeVideoClip(clips, size=size)
|
||||
composite.preview()
|
||||
composite.write_videofile(output_path, logger=None, threads=parallelism)
|
||||
|
||||
def filter_moments(moments, min_length, max_length):
|
||||
return [m for m in moments if m.get_duration() > min_length and m.get_duration() < max_length]
|
||||
|
Loading…
x
Reference in New Issue
Block a user