Skip to content

Instantly share code, notes, and snippets.

@lilithebowman
Last active August 2, 2018 13:15
Show Gist options
  • Save lilithebowman/76a132b1c85a073f8beabd3207d14404 to your computer and use it in GitHub Desktop.
Save lilithebowman/76a132b1c85a073f8beabd3207d14404 to your computer and use it in GitHub Desktop.
echo "You must download ffmpeg to use this shell script.
https://www.johnvansickle.com/ffmpeg/
Only this version will work because the default packages do not contain vidstab.
A terminal will pop up and churn for a while depending on the size
Add the list of files to concatenate to mylist.txt with "file " in front of the name. One per line.
Example:
file GOPR2307.MP4
file GP012307.MP4
file GP022307.MP4
This batch file will automatically concatenate, speed up the video 4x, and run extensive stabilization on the video.
"
start=`date +%s`
echo "Start timestamp $start"
mkdir /tmp/vid
echo "##### RUN CONCATENATION #####"
ffmpeg -f concat -safe 0 -i mylist.txt -c copy /tmp/vid/concatenated.mp4
echo "##### RUN STABILIZE - CALCULATE TRV #####"
ffmpeg -f mp4 -i /tmp/vid/concatenated.mp4 -strict -2 -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=concatenated.trf -f null -
echo "##### RUN STABILIZE - STABILIZE VIDEO #####"
ffmpeg -i /tmp/vid/concatenated.mp4 -strict -2 -vf vidstabtransform=input=concatenated.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy /tmp/vid/stabilized_1x_speed_output.mp4
echo "##### RUN SPEEDUP 2X #####"
ffmpeg -f mp4 -i /tmp/vid/stabilized_1x_speed_output.mp4 -strict -2 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" /tmp/vid/concatenated_speedy_2x.mp4
echo "##### RUN SPEEDUP 4X #####"
ffmpeg -f mp4 -i /tmp/vid/concatenated_speedy_2x.mp4 -strict -2 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" /tmp/vid/concatenated_speedy_4x.mp4
echo "##### RUN SPEEDUP 6X #####"
ffmpeg -f mp4 -i /tmp/vid/concatenated_speedy_4x.mp4 -strict -2 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" concatenated_speedy_6x.mp4
end=`date +%s`
echo "End timestamp $end"
runtime=$((end-start))
hms=$(date -u -d @${runtime} +"%T")
echo "Time to concatenate, speed up 4x, and smooth video: ($hms)"
echo "\n\n"
read -n 1 -s -r -p "Press any key to DELETE ALL TEMPORARY VIDEOS in /tmp/vid"
rm -rf /tmp/vid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment