( Hevi | 2024. 09. 19., cs – 17:37 )

Szerkesztve: 2024. 09. 19., cs – 18:07

ffmpeg?

Claude

👨🏼‍💻: Can you create a slide show with ffmpeg from images with custom transitions? 

🤖: Certainly! I can help you create a slide show using FFmpeg with custom transitions between images. This is a great way to create dynamic presentations or video montages from still images. Let me provide you with a script that accomplishes this task.

This script creates a slideshow using FFmpeg with custom fade transitions between images. Here's a breakdown of what the script does:

  1. It sets variables for the input directory, output file, image display duration, and transition duration.
  2. It collects all JPG images from the specified directory.
  3. It creates a complex filter that applies a fade transition between each image.
  4. It uses FFmpeg to create the final video, applying the transitions and setting the duration for each image.

To use this script:

  1. Save it as a .sh file (e.g., create_slideshow.sh).
  2. Make it executable with chmod +x create_slideshow.sh.
  3. Edit the input_dir variable to point to your image directory.
  4. Adjust the duration and transition_duration variables as needed.
  5. Run the script with ./create_slideshow.sh.

This script assumes your images are in JPG format. If you have different formats, you'll need to modify the file extension in the script.

------

#!/bin/bash

# Set variables
input_dir="path/to/your/images"
output_file="output_slideshow.mp4"
duration=5  # Duration each image is displayed
transition_duration=1  # Duration of the transition effect

# Get all image files
images=(${input_dir}/*.jpg)

# Create a temporary file for the filter complex
filter_complex_file=$(mktemp)

# Start building the filter complex
echo "[0:v]format=rgba,fade=d=$transition_duration:t=in:alpha=1,setpts=PTS-STARTPTS+$duration/TB[v0];" > $filter_complex_file

# Process each image
for i in "${!images[@]}"; do
    next=$((i+1))
    if [[ $next -eq ${#images[@]} ]]; then
        next=0
    fi
    
    echo "[${next}:v]format=rgba,fade=d=$transition_duration:t=in:alpha=1,setpts=PTS-STARTPTS+$duration/TB[v$next];" >> $filter_complex_file
    
    if [[ $i -ne 0 ]]; then
        echo "[tmp][v$i]overlay,trim=duration=$duration[tmp$i];" >> $filter_complex_file
        echo "[tmp$i][v$next]overlay=shortest=1[tmp];" >> $filter_complex_file
    else
        echo "[v0][v$next]overlay=shortest=1[tmp];" >> $filter_complex_file
    fi
done

# Finalize the filter complex
sed -i '$ s/\[tmp\]/[v]/' $filter_complex_file

# Run FFmpeg command
ffmpeg -y \
    $(for img in "${images[@]}"; do echo "-loop 1 -t $((duration+transition_duration)) -i $img"; done) \
    -filter_complex_script $filter_complex_file \
    -map "[v]" \
    -c:v libx264 -pix_fmt yuv420p \
    $output_file

# Clean up temporary file
rm $filter_complex_file

----

Nem próbáltam ki, lehet hogy kicsit játszani kell a scripttel. Claude/ChatGPT biztos tud segíteni a testreszabásban.

----

Szerk: ha kell valami egyszerű UI is, azt is lehet generáltatni vele:

https://claude.site/artifacts/aed455f3-70de-4960-88d7-843180f128e5