Skip to content

Instantly share code, notes, and snippets.

@DogeVenci
Last active April 15, 2021 03:02
Show Gist options
  • Save DogeVenci/13c7d739dc53caa1657d431546de958e to your computer and use it in GitHub Desktop.
Save DogeVenci/13c7d739dc53caa1657d431546de958e to your computer and use it in GitHub Desktop.
sh ./scenesplit.sh inputfile.mp4
#/bin/bash
start=0;
count=0;
in="$1"
#bn="$(basename "$in")"
bn="out"
echo "=============================================================================="
echo "FILE START: $bn"
mkdir "./$bn"
echo "Finding Scene... this might take a while..."
ffmpeg -nostdin -ss 300 -i "$in" -filter:v "select='gt(scene,0.8)',showinfo" -f null - 2>"./$bn/ffout.tmp.txt"
echo "Filtering timestamp... this might take a while..."
grep showinfo "./$bn/ffout.tmp.txt" | grep pts_time:[0-9.]* -o | grep '[0-9]*\.[0-9]*' -o > "./$bn/timestamps.tmp.txt"
scenes=$(wc -l < "./$bn/timestamps.tmp.txt")
echo "Found $scenes scenes"
sleep 10
while IFS= read -r line; do
echo "---------------------------------------------------------------------------"
echo "SCENE START: $count/$scenes ($start,$line)"
ffmpeg -i "$in" -ss "$start" -to "$line" -nostdin -y -vcodec libx264 -acodec aac -g 120 -s 720x480 "./$bn/$bn.($count of $scenes).mp4"
echo "SCENE DONE:$count/$scenes ($start,$line)"
echo "---------------------------------------------------------------------------"
start=$line
count=$(($count+1))
sleep 1
done <"./$bn/timestamps.tmp.txt"
echo "---------------------------------------------------------------------------"
echo "LAST SCENE START:$count/$scenes ($start,end)"
ffmpeg -i "$in" -ss "$start" -nostdin -y -vcodec libx264 -acodec aac -g 120 -s 1280x720 -r 30 "./$bn/$bn.($count of $scenes).mp4"
echo "LAST SCENE DONE:$count/$scenes ($start,end)"
echo "---------------------------------------------------------------------------"
echo "FILE DONE: $bn"
echo "=============================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment