Script to cut adverts out of a video
by GPGAgent from LinuxQuestions.org on (#58PHN)
I've written a script that lets me cut bits out of a video but I think it could be slicker, basically thus script takes a filename, number of cuts (I don't usit tho') Start and end of first bit to keep, start and end of second bit to keep and so on up to five bits to keep.
Firstly I'd like to not have limit of just up to five bits to keep, and secondly how could the script be improved, here's the script:Code:#!/bin/bash
# usage:
# CutAndEncode.sh Filename Cuts Start1 End1 Start2 End2 Start3 End3 ... Start5 End5
cnt=1
for P in "$@"
do
case $cnt in
1) FN=$P;;
2) CUTS=$P;;
3) ST=$P;;
4) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN"
ffmpeg -ss $ST -to $EN -i "$FN" -vf "yadif" -aspect 4:3 -c:v libx265 -preset faster Tmp-$cnt.mp4;;
5) ST=$P;;
6) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN"
ffmpeg -ss $ST -to $EN -i "$FN" -vf "yadif" -aspect 4:3 -c:v libx265 -preset faster Tmp-$cnt.mp4;;
7) ST=$P;;
8) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
9) ST=$P;;
10) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
11) ST=$P;;
12) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
13) ST=$P;;
14) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
esac
cnt=$((cnt + 1))
done
echo "Now join the cuts"
ls Tmp*.mp4 | perl -ne 'print "file $_"' | ffmpeg -protocol_whitelist "file,pipe" -safe 0 -y -f concat -i - -codec copy $FN.mp4
echo "Now delete the temp files"
rm Tmp*.mp4Cheers folks


Firstly I'd like to not have limit of just up to five bits to keep, and secondly how could the script be improved, here's the script:Code:#!/bin/bash
# usage:
# CutAndEncode.sh Filename Cuts Start1 End1 Start2 End2 Start3 End3 ... Start5 End5
cnt=1
for P in "$@"
do
case $cnt in
1) FN=$P;;
2) CUTS=$P;;
3) ST=$P;;
4) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN"
ffmpeg -ss $ST -to $EN -i "$FN" -vf "yadif" -aspect 4:3 -c:v libx265 -preset faster Tmp-$cnt.mp4;;
5) ST=$P;;
6) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN"
ffmpeg -ss $ST -to $EN -i "$FN" -vf "yadif" -aspect 4:3 -c:v libx265 -preset faster Tmp-$cnt.mp4;;
7) ST=$P;;
8) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
9) ST=$P;;
10) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
11) ST=$P;;
12) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
13) ST=$P;;
14) EN=$P
echo "Cut $cnt of $FN start at $ST and end at $EN";;
esac
cnt=$((cnt + 1))
done
echo "Now join the cuts"
ls Tmp*.mp4 | perl -ne 'print "file $_"' | ffmpeg -protocol_whitelist "file,pipe" -safe 0 -y -f concat -i - -codec copy $FN.mp4
echo "Now delete the temp files"
rm Tmp*.mp4Cheers folks