Cut a video out of a long recording with fade in and out and volume normalization
#!/bin/bash | |
INFILE="input_video.mp4" | |
FPS=30 | |
get_seconds() { | |
local seconds=0 | |
IFS=":" read -ra T <<< "$1" | |
for x in "${T[@]}"; do | |
seconds=$(echo "$seconds * 60 + $x" | bc) | |
done | |
echo $seconds | |
} | |
if [[ "$#" -ne 3 ]]; then | |
echo "Usage: $0 <start time> <stop time> <out file name>" | |
exit 1 | |
fi | |
start="$1" | |
stop="$2" | |
outfname="$3" | |
framestart="$( echo "$(get_seconds $start) * $FPS / 1" | bc)" | |
framestop="$( echo "($(get_seconds $stop) - 1) * $FPS / 1" | bc)" | |
ffmpeg -i "$INFILE" -ss $start -to $stop \ | |
-vf 'fade=in:'${framestart}:$FPS', fade=out:'${framestop}:$FPS \ | |
-af 'afade=in:st='$(get_seconds $start)':d=1, afade=out:st='$( echo "$(get_seconds $stop) - 1" | bc)':d=1, loudnorm=dual_mono=true:print_format=summary:I=-18' \ | |
-c:v libx264 -ar 48000 -c:a aac \ | |
${outfname}.mkv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment