Advertisement
metalx1000

FFMPEG Find Scene Change and Split File

Nov 11th, 2024
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.44 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2024  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. file=$1
  20. fn=${1##*/}
  21. dir=${file%$fn}
  22. name=${fn%.*}
  23. ext=${fn#$name}
  24.  
  25. echo -n "Scanning ${file} ..."
  26. ffmpeg -i "$file" \
  27.     -filter:v "select='gt(scene,0.4)',showinfo" \
  28.     -f null \
  29.     - 2>&1 | tee ffout | while read l; do echo -n "."; done
  30.  
  31. echo ""
  32.  
  33. timestamps=(0)
  34. stamps=$(grep showinfo ffout | grep pts_time:[0-9.]* -o | grep [0-9.]* -o)
  35. timestamps+=($stamps)
  36.  
  37. timestamps+=($(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file"))
  38.  
  39. for ((i = 1; i < ${#timestamps[@]}; i++)); do
  40.     printf -v part '%02d' "$i"
  41.     echo ffmpeg -ss "${timestamps[i - 1]}" -to "${timestamps[i]}" -i "$file" "$dir$name-$part$ext"
  42. done
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement