From f19647472da959edcfe620b34cd75a359cc1c456 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 31 May 2019 17:29:44 -0400 Subject: [PATCH] Scale videos to same size and use a constant framerate in the filter_complex command. Also, use that rate as the final output rate. Was finding slippage of the mattes with mixes of 24 and 30 fps videos. --- README.md | 4 +++- bipack.sh | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 14ae071..2fe21a7 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,6 @@ This command will take video `A.mp4` and `B.mp4` as image sources while using `m This script started as a multi-command experiment that finally got reduced to a single command that leans heavily on ffmpeg's `maskmerge` filter: [Documentation](https://ffmpeg.org/ffmpeg-filters.html#maskedmerge) -Uses 1280x720 resolution and Apple ProRes 422 HQ as the output format, right now but change that easily in the script. Check it out! \ No newline at end of file +Uses 1280x720 resolution and Apple ProRes 422 HQ as the output format, right now but change that easily in the script. + +Videos at different framerates will cause "slippage" between the mattes and the images, so it's best to standardize those before running this script. The default rate is set to 24fps because it's been the lowest common denominator of the videos this was written for, but you should use a consistent framerate with all videos passed into this script. \ No newline at end of file diff --git a/bipack.sh b/bipack.sh index 3fbf7fa..53e6b7b 100644 --- a/bipack.sh +++ b/bipack.sh @@ -1,29 +1,29 @@ #!/bin/bash -#IMAGE1 A=${1} -#IMAGE2 B=${2} -#MATTE MATTE=${3} -#OUTPUT FILE OUTPUT_FILE=${4} CONTRAST=100 -SIZE="1280x720" -RATE=30 +W=1280 +H=720 +RATE=24 time ffmpeg -y -i $A -i $B -i $MATTE \ -filter_complex " - color=0x000000:size=$SIZE, format=rgb24[bla]; - [0] format=rgb24 [a]; - [1] format=rgb24 [b]; - [2] format=gray, smartblur=1, eq=contrast=$CONTRAST, format=rgb24 [maska]; - [2] format=gray, smartblur=1, eq=contrast=$CONTRAST, negate, format=rgb24 [maskb]; + color=0x000000:size=${W}x${H}, format=rgb24[bla]; + [0] fps=${RATE},scale=${W}:${H}:force_original_aspect_ratio=decrease,format=rgb24 [a]; + [1] fps=${RATE},scale=${W}:${H}:force_original_aspect_ratio=decrease,format=rgb24 [b]; + [2] fps=${RATE},scale=${W}:${H}:force_original_aspect_ratio=decrease,format=gray, + smartblur=1, eq=contrast=$CONTRAST, format=rgb24 [maska]; + [2] fps=${RATE},scale=${W}:${H}:force_original_aspect_ratio=decrease,format=gray, + smartblur=1, eq=contrast=$CONTRAST, negate, format=rgb24 [maskb]; [bla][a][maska] maskedmerge, format=rgb24 [pass1]; [pass1][b][maskb] maskedmerge, format=rgb24 " \ -r $RATE \ -c:v prores_ks \ + -shortest \ -profile:v 3 \ $OUTPUT_FILE