Watch a mashup of many video files

L=5; while true; do; readarray -t paths < <(find . -type f -print | shuf -n 1); for i in "${!paths[@]}"; do; path=${paths[i]}; if ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0" > /dev/null; then; N=$(ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0"); D=${N%.*}; P=$((D / 100 * 25)); R=$((1 + RANDOM % D - P * 2)); S=$((P + RANDOM % R)); W=$((R / 4)); LEN=$((1 + RANDOM % L)); mpv "$path" --start="$S" --length="$LEN" --fs &> /dev/null; W=$(bc <<< "$LEN - 0.5"); sleep "$W"; unset 'paths[i]'; fi; done; done

July 6, 2023krypniok

Explanation

The command expanded to multiple lines as if written in a script:

L=5    
while true; do
  readarray -t paths < <(find . -type f -print | shuf -n 1)
  for i in "${!paths[@]}"; do
    path=${paths[i]}
    if ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0" > /dev/null; then
      N=$(ffprobe -i "$path" -show_entries format=duration -v quiet -of csv="p=0")
      D=${N%.*}
      P=$((D / 100 * 25))
      R=$((1 + RANDOM % D - P * 2))
      S=$((P + RANDOM % R))
      W=$((R / 4))
      LEN=$((1 + RANDOM % L))
      mpv "$path" --start="$S" --length="$LEN" --fs &> /dev/null
      W=$(bc <<< "$LEN - 0.5")
      sleep "$W"
      unset 'paths[i]'
    fi
  done
done

Usage:

  • Open a terminal
  • Change to the directory in which you have videos
  • Run the command, changing "L=5" to some other seconds

Limitations

The script assumes several non-standard utilities are installed in the system:

  • shuf
  • ffmpeg
  • mpv