Skip to content

Instantly share code, notes, and snippets.

@Behinder
Created September 19, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Behinder/068159b32f736a806e55132ef322ed59 to your computer and use it in GitHub Desktop.
Save Behinder/068159b32f736a806e55132ef322ed59 to your computer and use it in GitHub Desktop.
Cut commercials from the video file and join files
#!/usr/bin/env bash
NAZWA="$(basename "$1" | sed 's/\(.*\)\..*/\1/')"
echo "Generating split command\n"
KOMENDA="tr -d '\n' < \"$NAZWA.ffsplit\""
STRING=`eval $KOMENDA`
echo $STRING
#echo "ffmpeg -i \"$1\""
eval "ffmpeg -i \"$1\" $STRING"
echo "Done split"
echo "Generate merge command"
#First counting line in ffsplit file
ILE="wc -l < \"$NAZWA.ffsplit\""
ILEWYNIK=`eval $ILE`
if [ -n "$2" ]; then
CODEC=$2
else
CODEC="libx264"
fi
if [ $ILEWYNIK -lt 10 ]; then
STRING="ffmpeg -i \"concat:"
for (( i=0;i<$ILEWYNIK-1;i++ )) ;
do
STRING=$STRING"segment00$i.ts|"
done
else
STRING="ffmpeg -i \"concat:"
for (( i=0;i<9;i++ )) ;
do
STRING=$STRING"segment00$i.ts|"
done
for (( i=10;i<=$ILEWYNIK-1;i++ )) ;
do
STRING=$STRING"segment0$i.ts|"
done
fi
KOMENDA=$STRING"\" -c:v $CODEC -c:a ac3 -f mpegts output.mpg"
echo $KOMENDA
echo "Starting merge segments"
eval "$KOMENDA"
echo "Done.Removing segments"
rm segment*.ts
mv output.mpg "_$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment