Muddyblack k
Muddyblack k

Reputation: 254

Debian LITE Smooth Slide Show

I'm interested in utilizing my Raspberry Pi 3 for advertising purposes. I'd like to create a slideshow that can display both videos and images, and I want to be able to iterate through all the media files located in a specific folder, as I have limited control over the network and need to retrieve these files from a cloud source.

I currently have a code snippet that uses fbiand vlc to achieve this, but I'm facing an issue where the command-line briefly appears after each image transition. After video there is no such problem.

I've managed to mitigate this issue with the clear command, but it's still bothering me. I'm wondering if anyone has suggestions for a smoother way to accomplish this without the command-line interruptions.

Here my codesnipped:

#!/bin/bash

# Define the directory where your images are stored
MEDIA_FOLDER="/home/pi/slide_show/test"

# Create an array of media files
media_files=("$MEDIA_FOLDER"/*.{jpg,jpeg,png,gif,mp4})

clear
setterm -cursor off

# Iterate through media files and display them
while true; do
    for media_file in "${media_files[@]}"; do
        if [[ -f "$media_file" ]]; then
            if [[ "$media_file" == *.mp4 ]]; then
                vlc -f --one-instance --no-xlib -I dummy "$media_file" vlc://quit >/dev/null 2>&1
            else
                clear
                fbi -a -b -u -noverbose -1 -t 5 "$media_file" >/dev/null 2>&1
                clear
            fi
        fi
    done
done

UPDATE:

So I now have at least a smooth way for images. When switching between image and video there is still a short amount of time a black screen.

DISPLAYTIME=10
MEDIA_FOLDER=""

# Function to kill display processes
killer() {
    sudo pkill -9 -x "fbi"
    sudo pkill -x "mpv"
    sleep 2
}

# Function to display images and videos in terminal
display() {
    local image_files="$1"
    local video_files="$2"
    killer

    if [[ -n "$image_files" && -n "$video_files" ]]; then
        while true; do
            sudo fbi -a -r 5 -t $DISPLAYTIME -T 1 --noverbose -1 $image_files >/dev/null 2>&1 &
            disown
            sleep $((IMAGE_FILES_COUNT * DISPLAYTIME))
            pkill -9 -x "fbi" >/dev/null 2>/dev/null &
            mpv --fs --cache-secs=10 --fs-screen=1 "$video_files" >/dev/null 2>&1
            clear
        done
    elif [ -n "$image_files" ]; then
        clear
        sudo fbi -a -r 5 -t $DISPLAYTIME -T 1 --noverbose $image_files >/dev/null 2>&1
    elif [ -n "$video_files" ]; then
        clear
        mpv --fs --cache-secs=10 --loop=inf --fs-screen=1 "$video_files" >/dev/null 2>&1
    fi
}

# Function to handle the main display logic
handle_display() {
    local image_files=$(find "$MEDIA_FOLDER" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \))
    local video_files=$(find "$MEDIA_FOLDER" -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.ogg" -o -iname "*.mov" \))
    display "$image_files" "$video_files"
}

# Function to handle the main loop
main_loop() {
    while true; do
        sudo kill "$DISPLAYPID"
        sleep 2
        killer
        if [ -d "$MEDIA_FOLDER" ] && [ "$(ls -A "$MEDIA_FOLDER")" ]; then
            handle_display &
            DISPLAYPID=$!
        else
            killer
            clear
        fi
        sleep 10
    done
}

Upvotes: 1

Views: 239

Answers (1)

Dudi Boy
Dudi Boy

Reputation: 4900

Suggesting to avoid looping each image in vlc.

And use vlc to slide show the entire directory IMAGES_DIR.

vlc -I dummy --dummy-quiet "${IMAGES_DIR}" --slide-show-delay 5
  • -I dummy: The -I option specifies the interface to use. dummy is one of VLC's interfaces. It's a minimalistic interface without any visual elements, which is useful when you want to use VLC for tasks like this where you don't need the full graphical interface.

  • --dummy-quiet: This option suppresses unnecessary output from the dummy interface. It makes the command run more quietly, without filling your terminal or command prompt with messages from VLC.

  • IMAGES_DIR: This is a placeholder for the directory that contains the images you want to display.

  • --slide-show-delay 5: This option sets the delay between images in the slideshow. The number after --slide-show-delay is the delay in seconds. In this case, each image will be displayed for 5 seconds before moving on to the next one.

If your folder contain non pictures files (audio, video). Copy the images files to designated folder `IMAGES_DIR'. Therefore your script should simplify like this:

#!/bin/bash

# Define the directory where your images are stored
MEDIA_FOLDER="/home/pi/slide_show/test"
IMAGES_DIR="${MEDIA_FOLDER}"/images

# Create a dir for images under MEDIA_FOLDER
mkdir -p "${IMAGES_DIR}"
cp "${MEDIA_FOLDER}"/*.{jpg,jpeg,png,gif,mp4} "${IMAGES_DIR}"

clear
setterm -cursor off

# Iterate through media files and display them
while true; do
   # optional sync IMAGES_DIR for any changes in the MEDIA_FOLDER using rsync command
   # rsync -av --include='*.jpg' --include='*.jpeg' --include='*.png' --include='*.gif' --include='*.mp4' --exclude='*' "${MEDIA_FOLDER}/" "${IMAGES_DIR}/"
   vlc -I dummy --dummy-quiet "${IMAGES_DIR}" --slide-show-delay 5
done

Upvotes: 1

Related Questions