Last active
August 29, 2015 13:58
-
-
Save DASPRiD/10006136 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
#!/bin/bash | |
# Timelapse script by Ben Scholzen 'DASPRiD' | |
# Licensed under the Simplified BSD License | |
# http://opensource.org/licenses/BSD-2-Clause | |
FFPROBE=/usr/bin/ffprobe | |
FFMPEG=/usr/bin/ffmpeg | |
SOXI=/usr/bin/soxi | |
SPLASH_LENGTH=5 | |
INPUT_SPLASH=$1 | |
INPUT_VIDEO=$2 | |
INPUT_AUDIO=$3 | |
OUTPUT_FILE=$4 | |
VIDEO_LENGTH=$($FFPROBE -i "$INPUT_VIDEO" 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F':' '{print $1 * 60 * 60 + $2 * 60 + $3}') | |
AUDIO_LENGTH=$($SOXI -D "$INPUT_AUDIO") | |
PTS=$(echo "scale = 15; 1 / ($VIDEO_LENGTH / ($AUDIO_LENGTH - $SPLASH_LENGTH))" | bc | awk '{printf "%.15f", $0}') | |
# First we will create the splash video part in a lossless format | |
SPLASH_TEMP=$(mktemp --suffix=.mp4) | |
$FFMPEG -loop 1 -i "$INPUT_SPLASH" -t $SPLASH_LENGTH -c:v libx264 -pix_fmt yuv420p -preset ultrafast -qp 0 -y "$SPLASH_TEMP" | |
# Then create the final timelapse | |
$FFMPEG \ | |
-i "$SPLASH_TEMP" \ | |
-i "$INPUT_VIDEO" \ | |
-i "$INPUT_AUDIO" \ | |
-filter_complex "[1:v]setpts=$PTS*PTS [tl]; [0:v] [tl] concat=n=2:v=1:a=0 [v]" \ | |
-map '[v]' -map 2:0 \ | |
-codec:v libx264 -pix_fmt yuv420p -profile:v high -preset slow -b:v 4m -maxrate 4m -bufsize 8m -threads 0 \ | |
-codec:a libvo_aacenc -b:a 192k -ac 2 -ar 48000 \ | |
-shortest \ | |
-y \ | |
"$OUTPUT_FILE" | |
rm -f "$SPLASH_TEMP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment