Skip to content

Instantly share code, notes, and snippets.

@luxigo
Created October 4, 2020 03:13
Show Gist options
  • Save luxigo/bcebfcc5d01bd73fb4717cf8fa76f9ca to your computer and use it in GitHub Desktop.
Save luxigo/bcebfcc5d01bd73fb4717cf8fa76f9ca to your computer and use it in GitHub Desktop.
Blend original video with edge detection filter output using multiply operator with ffmpeg, and accelerate slow motion video/audio
#!/bin/bash
INPUT=$1
OUTPUT=$2
# the settings below converts from 480fps played at 30fps (1/8 speed slowmotion from Galaxy S9+)
# to 1/2 speed slow motion video at 60fps
SPEED_FACTOR=4
OUTPUT_FRAMERATE=60
FACTOR=$(printf %.3f "$((10**3 * 1/$SPEED_FACTOR))e-3")
if [ -z "$OUTPUT" ] ; then
EXT=${INPUT##*.}
BASENAME=$(basename -- $INPUT .$EXT)
OUTPUT=$(dirname $INPUT)/$BASENAME-composite.$EXT
fi
# to add some processing steps using filter_complex below (eg color correction)
# check https://ffmpeg.org/ffmpeg-filters.html
ffmpeg \
-i "$INPUT" \
-filter_complex " \
[0:v]setpts=$FACTOR*PTS[vid];
[0:a]atempo=$SPEED_FACTOR;
[0:v]setpts=$FACTOR*PTS,sobel=planes=0xf:scale=1,negate [sob]; \
[vid][sob]blend=all_mode=multiply \
" \
-preset veryslow \
-tune film \
-r $OUTPUT_FRAMERATE \
-crf 15 \
-c:a aac \
-b:a 128k \
-pix_fmt yuv420p \
-movflags \
+faststart \
"$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment