• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Support General Questions Generate backdrops from screenshots?

     
    • 0 Vote(s) - 0 Average

    Generate backdrops from screenshots?

    Similar to how missing poster art is generated
    theguymadmax
    Offline

    Community Moderator

    Posts: 1,187
    Threads: 0
    Joined: 2024 Jun
    Reputation: 61
    #6
    2024-07-18, 05:22 PM
    (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.")
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    Messages In This Thread
    Generate backdrops from screenshots? - by stewed pork roti - 2024-07-14, 09:17 PM
    RE: Generate backdrops from screenshots? - by esjaysee - 2024-07-14, 10:09 PM
    RE: Generate backdrops from screenshots? - by Efficient_Good_5784 - 2024-07-14, 11:21 PM
    RE: Generate backdrops from screenshots? - by stewed pork roti - 2024-07-18, 06:08 AM
    RE: Generate backdrops from screenshots? - by Efficient_Good_5784 - 2024-07-18, 06:49 AM
    RE: Generate backdrops from screenshots? - by theguymadmax - 2024-07-18, 05:22 PM

    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode