Last active
January 28, 2020 11:38
-
-
Save paulwinex/b5c5e1904a13c3d46175308dbe0753dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_movie(self, source_dir: Path, output_path: Path, **kwargs): | |
# получаем исходные данные | |
# основной сиквенс | |
sequence_path = self.get_source_sequence(source_dir) # путь к сиквенсу с паддингом | |
fps = self.get_value('fps', **kwargs) | |
if not fps: | |
raise RuntimeError('FPS for build movie not set') | |
# вставка в начале | |
pre_frames = self.collect_sequence_from(source_dir / self.variables['build_pre_frames_dir']) | |
# вставка в конце | |
post_frames = self.collect_sequence_from(source_dir / self.variables['build_post_frames_dir']) | |
# расрешение дейлиза | |
output_resolution = expressions.str_to_list(kwargs.get('output_resolution') \ | |
or self.kwargs.get('output_resolution') \ | |
or self.variables['output_resolution']) | |
# файл звука | |
sound_file = self.variables['job_meta'].get('sound') | |
# базовый офсет | |
sound_offset = self.get_value('source_sound_offset', **kwargs) | |
# таймкод | |
timecode = self.get_value('timecode', **kwargs) | |
# аргументы рендера | |
output_args = [str(output_path)] | |
output_kwargs = dict(pix_fmt='yuv420p', vcodec='libx264') | |
if timecode: | |
output_kwargs['timecode'] = timecode | |
# начало сборки пайпа | |
main_sq = ffmpeg.input(sequence_path).filter('scale', *output_resolution).filter('fps', fps=fps) | |
if pre_frames: | |
logger.debug('Add pre frames from: %s', pre_frames) | |
# вставка в начале | |
pre_stream = ffmpeg.input(pre_frames).filter('scale', *output_resolution).filter('fps', fps=fps) | |
main_sq = ffmpeg.concat(pre_stream, main_sq) | |
# TODO: поправить офсет звука на длину pre_frames | |
if post_frames: | |
logger.debug('Add post frames from: %s', post_frames) | |
# вставка в конце | |
post_frames = ffmpeg.input(post_frames).filter('scale', *output_resolution).filter('fps', fps=fps) | |
main_sq = ffmpeg.concat(main_sq, post_frames) | |
if sound_file: | |
# звук | |
logger.debug('Add sound file from %s', sound_file) | |
audio_args = {} | |
if sound_offset: | |
# применение офсета | |
audio_args['itsoffset'] = sound_offset | |
audio = ffmpeg.input(sound_file, **audio_args) | |
output_args.insert(0, audio) | |
# сборка всх элементов и параметров аутпута | |
out = main_sq.output(*output_args, **output_kwargs) | |
# рендер | |
logger.info('CMD: ffmpeg %s', ' '.join(out.get_args())) | |
out.run(overwrite_output=True) | |
return output_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment