Last active
December 6, 2021 09:48
-
-
Save MrSimbax/44c2ed466c82893f2119fd4bfad37bb7 to your computer and use it in GitHub Desktop.
This script uses ffmpeg to cut a video without losing much quality
This file contains 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/sh | |
# This script uses ffmpeg to cut a video without losing much quality | |
me=`basename "$0"` | |
# Check if necessary parameters were passed | |
if [ -z "$1" -o -z "$2" -o -z "$3" ]; then | |
echo "Usage: $me INPUT BEGIN END [OUTPUT=Dropbox]"; | |
exit 0 | |
fi | |
# Get parameters | |
input=$1 | |
begin=$2 | |
end=$3 | |
output=$4 | |
# Set output to Dropbox if not given | |
filename=`basename "$input"` | |
if [ -z "$output" ]; then | |
timestamp=`date +%F_%H-%M-%S`; | |
output="$HOME/Dropbox/Public/Videos/$timestamp"_"$input" | |
fi | |
echo $output | |
# Create output directory if it doesn't exist | |
output_dir=`dirname "$output"` | |
mkdir -p $output_dir | |
# Finally, cut the video | |
ffmpeg -hide_banner -ss $begin -i "$input" -codec copy -copyts -to $end -avoid_negative_ts make_zero "$output" | |
# It would be cool if share link to Dropbox was automatically copied, but it's not that easy | |
# (Lack of "share" command in Dropbox CLI + authentication required) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment