Jellyfin Forum
Generate backdrops from screenshots? - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: General Questions (https://forum.jellyfin.org/f-general-questions)
+--- Thread: Generate backdrops from screenshots? (/t-generate-backdrops-from-screenshots)



Generate backdrops from screenshots? - stewed pork roti - 2024-07-14

Can the screen grabber be used to also generate backdrops for certain media types? I have a library of concert recordings and I'd like to use a random screenshot as the backdrop, instead of the plain black bg.

If there isn't a built in function or a plugin, does anyone know of an external tool that can do this?


RE: Generate backdrops from screenshots? - esjaysee - 2024-07-14

I have a few concerts that all have images. In the Library settings, go to Chapter Images and check both boxes. That should make a generic screenshot of the video as the thumbnail. Then you can go to Edit Images and use it as the backdrop. I might be missing a step but I think that's how I did it.


RE: Generate backdrops from screenshots? - Efficient_Good_5784 - 2024-07-14

(2024-07-14, 10:09 PM)esjaysee Wrote: I have a few concerts that all have images.  In the Library settings, go to Chapter Images and check both boxes.  That should make a generic screenshot of the video as the thumbnail.  Then you can go to Edit Images and use it as the backdrop.  I might be missing a step but I think that's how I did it.
I just checked. You cannot reach the chapter images from the edit images option.
The user would need to find the exact folder in the config/metadata/library directory to copy the chapter images.

What would be more easier is to just open the concert video with an external player on the PC (VLC, MPV, etc.) and screenshot it. Then simply just upload the screenshot as the background for the concert in Jellyfin.


RE: Generate backdrops from screenshots? - stewed pork roti - 2024-07-18

So no built-in way to do it with Jellyfin, then? I've got a pretty big folder of music videos and concerts, so the best I can think of is to write a bash script and take screenshots with ffmpeg at a random time.

The Mediaelch app kind of does this, but you have to set your folder as "Movies" instead of "Concerts" and then you'd have to click it for each one. Not ideal, but better than nothing.

Let me know if anybody finds something to do this efficiently, and I'll let you know if I ever write that script Smiling-face


RE: Generate backdrops from screenshots? - Efficient_Good_5784 - 2024-07-18

(2024-07-18, 06:08 AM)stewed pork roti Wrote: ...so the best I can think of is to write a bash script and take screenshots with ffmpeg at a random time.

As an FYI, the episode screen grabber in Jellyfin isn't actually random. It pulls an image from the same video duration percentage (I think) each time. It will not randomly pick a picture from any point in the video, so even if you recreate them, they come out the same.


RE: Generate backdrops from screenshots? - theguymadmax - 2024-07-18

(2024-07-18, 06:08 AM)stewed pork roti Wrote: Let me know if anybody finds something to do this efficiently, and I'll let you know if I ever write that script Smiling-face

This python script should do the job, adjust to your needs. It's set to create three backdrops; one at 20 & 40 seconds and one random within the first 5 minutes. Just set the script to be executable and run it without passing any arguments. Requirements: Python3 & FFmpeg.

Code:
#!/usr/bin/env python3

import os
import random
import subprocess
from pathlib import Path

def extract_frames(input_file, output_prefix, first_file):
    # Define times to extract frames (in seconds)
    times = [20, 40]
    random_time = random.randint(60, 300)  # Random time between 60 and 300 seconds
    times.append(random_time)

    for i, time in enumerate(times):
        if i == 0 and first_file:
            output_file = f"{output_prefix}-backdrop.jpg"  # First file without number sequence
        else:
            output_file = f"{output_prefix}-backdrop{i+1}.jpg"  # Subsequent files with number sequence

        output_path = os.path.join(os.path.dirname(input_file), output_file)
        subprocess.run(['ffmpeg', '-hide_banner', '-loglevel', 'error',
                        '-i', input_file, '-ss', str(time), '-vframes', '1', output_path])
        print(f"Processed: {output_file}")

def process_media_file(media_file):
    filename = media_file.name
    print(f"Processing: {filename}")
    filename_no_ext = filename[:filename.rfind('.')]
    output_prefix = f"{filename_no_ext}"
    extract_frames(str(media_file), output_prefix, first_file=True)

def scan_directory(directory):
    media_files = []
    for root, _, files in os.walk(directory):
        for file in files:
            if any(file.lower().endswith(ext) for ext in ['.mp4', '.avi', '.mkv', '.mov']):
                media_files.append(Path(root) / file)

    total_files = len(media_files)
    print(f"Total media files found: {total_files}")
    for media_file in media_files:
        process_media_file(media_file)

if __name__ == "__main__":
    directory = input("Enter the directory path where media files are located: ").strip()

    if not os.path.isdir(directory):
        print("Invalid directory path.")
        exit()

    scan_directory(directory)
    print("Frame extraction completed.")