Last active
November 15, 2021 15:08
-
-
Save NassimBentarka/7aa9693452b02e6397116c3465df69a5 to your computer and use it in GitHub Desktop.
Trim Videos from any format using FFMPEG in copy-paste speeds!
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/bash | |
#Author: Nassim BENTARKA (NBN) @nassimosaz | |
#You can implement this tool into your system by copying the script into ~/bin/ directory as fast-video-trim | |
if [ $# -ne 4 ]; then | |
printf "\n${0}: usage: Fast-Video-Trim.sh [BEGIN_TIME HH:MM:SS:] [END_TIME HH:MM:SS] [INPUT_FILE] [OUTPUT_FILE]\n\n" | |
exit 1 | |
fi | |
TIME1=$1 | |
TIME2=$2 | |
IN=$3 | |
OUT=$4 | |
if [ ! -f "$3" ]; then | |
echo "File $3 does not exist!" | |
exit 1 | |
fi | |
if [ -f "$4" ]; then | |
printf "RISK! File $4 will be overwritten!\n" | |
read -p "Continue? (y/n) " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
continue | |
else | |
exit 1 | |
fi | |
else | |
# Convert the times to seconds from the Epoch | |
SEC1=`date +%s -d $1` | |
SEC2=`date +%s -d $2` | |
# Use expr to do the math, let's say TIME1 was the start and TIME2 was the finish | |
DIFFSEC=`expr ${SEC2} - ${SEC1}` | |
#The main ffmpeg command | |
ffmpeg -v quiet -stats -i $3 -ss ${TIME1} -t ${DIFFSEC} -c copy $4 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, make the script executable by running: chmod +x Fast-Video-Trim.sh
usage example: ./Fast-Video-Trim.sh 00:00:47 00:08:15 input_file.foo output_file.foo
usage: Fast-Video-Trim.sh [BEGIN_TIME HH:MM:SS] [END_TIME HH:MM:SS] [INPUT_FILE] [OUTPUT_FILE]