Skip to content

Instantly share code, notes, and snippets.

@htchaan
Created April 13, 2017 17:47
Show Gist options
  • Save htchaan/3eaf4e547ab0452c41b3a2f76781a57f to your computer and use it in GitHub Desktop.
Save htchaan/3eaf4e547ab0452c41b3a2f76781a57f to your computer and use it in GitHub Desktop.
join-gopro-clips.sh
#!/bin/sh
# example usage:
# . join-gopro-clips.sh /f/DCIM/111GOPRO/*574*MP4
# this will generate and execute a ffmpeg command:
# /cygdrive/c/ProgramData/chocolatey/bin/ffmpeg -i 'F:\DCIM\111GOPRO\GOPR0574.MP4' -filter_complex '[0:v]scale=-1:720[v0];[v0][0:a]concat=n=1:v=1:a=1[v][a]' -r 18 -pix_fmt yuv420p -map '[v]' -map '[a]' -vcodec libx264 -preset veryslow 'C:\Temp\GOPR0574.MP4'
#function join-gopro-clips() {
i=0
c=$(which ffmpeg)
for f in "$@"; do ((++i)) && c="${c} -i $f"; done
#for f in "$@"; do ((++i)) && c="${c} -i '$(cygpath -w -- $f)'"; done # for cygwin
f=''
for (( j = 0; j < i; j++ )); do f="${f}[${j}:v]scale=-1:720[v${j}];"; done
for (( j = 0; j < i; j++ )); do f="${f}[v${j}][${j}:a]"; done
# for (( j = 0; j < i; j++ )); do f="${f}[${j}:v]"; done
f="${f}concat=n=${i}:v=1:a=1[v][a]"
c="${c} -filter_complex '${f}' -r 18 -pix_fmt yuv420p -map '[v]' -map '[a]' -vcodec libx264 -preset veryslow $(basename $1)"
#c="${c} -filter_complex '${f}' -r 18 -pix_fmt yuv420p -map '[v]' -map '[a]' -vcodec libx264 -preset veryslow '$(cygpath -w -- $(pwd)/$(basename $1))'" # for cygwin
echo $c
eval $c
touch -r $1 $(basename $1)
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment