ffmpeg-frame-showcase.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash -x
  2. set -euo pipefail # bash strict mode
  3. # #!/usr/bin/env bash
  4. set -euo pipefail # bash strict mode
  5. basename=${1##*/}
  6. noext=${basename%.*}
  7. directory="/tmp/your/path/${noext}"
  8. mkdir -p "$directory"
  9. length="$(ffprobe -i "$1" -show_entries format=duration -v quiet -of csv='p=0')"
  10. image_count=$( echo "l(${length})/l(1.2)" | bc -l)
  11. framerate=$(ffprobe -v 0 -of csv="p=0" -select_streams V:0 -show_entries stream=r_frame_rate "$1")
  12. step=$( echo "${length}/${image_count}" | bc -l)
  13. round(){
  14. echo "(${1}+0.5)/1" | bc
  15. }
  16. # for (( i=0; i<$(round $length) ; i+=$(round $step) )); do
  17. # for (( i=0; i<$(round $length) ; i+=$(round $image_count) )); do
  18. # timestamp=$(date -u -d "@${i}" "+%H:%M:%S")
  19. # ffmpeg -y -i "$1" -ss "$timestamp" -vframes 1 -vcodec png -an -y "${directory}/${timestamp}.png"
  20. # mogrify -fill red -pointsize 100 \
  21. # -draw "text 50,50 '${timestamp}'" \
  22. # "${directory}/${timestamp}.png"
  23. # done
  24. # montage "${directory}/*" -geometry +10+10 grid.png
  25. # https://askubuntu.com/questions/874042/how-to-make-screenshot-gallery-from-command-line
  26. rows=$(round "sqrt(${image_count})")
  27. cols=$((rows + 1))
  28. frames=$(round "(${framerate})*${image_count}")
  29. ffmpeg -i "$1" -frames 1 \
  30. -vf "select=not(mod(n\,${frames})),scale=-1:240,tile=${rows}x${cols}" \
  31. grid.png
  32. # ffmpeg -i "$1" -frames 1 -vf "select=not(mod(n\,1000)),scale=-1:240,tile=2x3" out.png
  33. # I'd use "ffmpeg" to do this. A command to extract PNG images at X intervals can be as simple as this...
  34. # ffmpeg -i input.mp4 -r 1 out%04d.png
  35. # Using the option -r 1 will set the output frame rate to 1 every second. Assuming the input video has a frame rate of 25 per second, the option -r 1 will output about every 25th frame. Calculate the interval you need according to the frame rate of the input. For example, to get approximately every 10th frame, use -r 2.5.
  36. # The output file name in this example contains %04d, which creates a numbered sequence with four digits, padded with leading zeros.