Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
#cut/join videos using ffmpeg without quality loss
if [ "$(uname)" == "Darwin" ]; then
if ! [ -x "$(command -v brew)" ]; then
echo 'homebrew is not installed.'
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
if ! [ -x "$(command -v ffmpeg)" ]; then
echo 'ffmpeg is not installed.'
brew install ffmpeg
fi
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if ![ -x "$(command -v ffmpeg)" ]; then
echo 'ffmpeg is not installed.'
fi
fi
if [ -z $1 ] || [ -z $2 ]; then
echo "Usage:$0 c[ut] seconds <File>"
echo " eg. $0 c 10 80 example.mp4"
echo " eg. $0 c 00:00:10.100 00:01:20.200 example.mp4"
echo "Usage:$0 j[oin] <FileType>"
echo " eg. $0 j avi"
exit
fi
case "$1" in
c)
echo "cuttig video..."
echo $4
fileName=$(echo $4 | rev | cut -f 2- -d '.' | rev)
fileType=$(echo $4 | rev | cut -f 1 -d '.' | rev)
echo $fileName
echo $fileType
startTime=$( echo "$2" | tr ':' '_')
endTime=$( echo "$3" | tr ':' '_' )
echo $escapedFileName
ffmpeg -i "$4" -ss $2 -to $3 -acodec copy -vcodec copy "$fileName-$startTime-$endTime.mp4"
;;
j)
echo "joinning videos..."
rm temp_list.txt
for f in `ls *.$2 | sort -k 1n -t '.'`; do echo "file '$f'" >> temp_list.txt; done
#printf "file '%s'\n" ./*.$2 > temp_list.txt
ffmpeg -f concat -i temp_list.txt -c copy output.$2
rm temp_list.txt
;;
*)
echo "wrong arguments"
;;
esac
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment