In the beginning was the Word, and the Word was with God, and the Word was God. The same was in the beginning with God. All things were made by him; and without him was not any thing made that was made. In him was life; and the life was the light of men. And the light shineth in darkness; and the darkness comprehended it not. John 1:1-5 (KJV)
#!/bin/bash # Show slideshow from videos in current directory # Save random frame from random video in current working directory as PNG image # How many screenshots? playframes=30 # How long to show each screenshot, in seconds? sleeptime=3 # What is the maximum character count you want in filename? length=40 ### clear for (( i=1; i<=playframes; i++ )) do mapfile -t video_files_array < <(find . -type f -iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.mkv" -o -iname "*.mpeg" -o -iname "*.mpg" -o -iname "*.wmv" -o -iname "*.webm" -o -iname "*.flv" -o -iname "*.ogv" -o -iname "*.m4v" -o -iname "*.m2t") # Check if the array is not empty if (( ${#video_files_array[@]} == 0 )); then echo "No video files found in the current directory." else # Get a random index random_index=$(( RANDOM % ${#video_files_array[@]} )) # Echo a random filename from the array video="${video_files_array[random_index]}" fi # Remove the './' prefix if it exists video="${video#./}" echo -e "Video = \e[33m$video\e[0m" # select first X characters of filename for constructing the image name truncated_video="${video:0:length}" # Remove the file extension truncated_video="${truncated_video%.*}" duration=$(ffprobe -v error -show_entries format=duration -of default=nokey=1:noprint_wrappers=1 "$video") # round off to a whole number duration=$(printf "%.0f" "$duration") echo "duration = "$duration # Generate a random whole number between 0 and duration (inclusive) random_time=$((RANDOM % (duration + 1))) echo "random time: "$random_time # Construct filename for framegrab in the current directory framegrab="$(pwd)/${truncated_video}_${random_time}_seconds.png" echo -e "framegrab = \e[33m$framegrab\e[0m" # Check if the file specified by $framegrab was written if [ -e "$framegrab" ]; then echo -e "File already exists: \033[32m$framegrab\033[0m" ffmpeg_flag="NO" else echo "Creating file" ffmpeg_flag="YES" fi # Only run ffmpeg if the image does not already exist if [ "$ffmpeg_flag" != "NO" ]; then # Create PNG image ffmpeg -hide_banner -ss "$random_time" -i "$video" -frames:v 1 -n "$framegrab" fi # Show the image in full-screen echo "Attempting to play: ${framegrab}" ffplay -loglevel quiet -fs -i "${framegrab}" & sleep $sleeptime # Kill the older ffplay process kill $FFPLAY_OLD # Extract the filename from the full path filename=$(basename "$framegrab") mv "$framegrab" "$filename" echo "image moved to $(pwd)" # Store the PID FFPLAY_OLD=$! done # Close the last image shown kill $FFPLAY_OLD
Jun 8, 2025, 10:12:51 PM | by Admin