Skip to content

Instantly share code, notes, and snippets.

@windworst
Forked from imcaspar/videocj.sh
Last active April 11, 2018 16:28
Show Gist options
  • Save windworst/9a3bf1dbac25a7f85f2f58742a56d5bd to your computer and use it in GitHub Desktop.
Save windworst/9a3bf1dbac25a7f85f2f58742a56d5bd to your computer and use it in GitHub Desktop.
edit display
#!/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
name=$(basename $0)
if [ -z $1 ] || [ -z $2 ]; then
echo "Usage:$name c[ut] seconds <File>"
echo " eg. $name c 10 80 example.mp4"
echo " eg. $name c 00:00:10.100 00:01:20.200 example.mp4"
echo "Usage:$name j[oin] <FileType>"
echo " eg. $name 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