Skip to content

Instantly share code, notes, and snippets.

@yadex205
Last active May 15, 2024 13:54
Show Gist options
  • Save yadex205/4512716a15e17c76e0b58fd3e09a1f13 to your computer and use it in GitHub Desktop.
Save yadex205/4512716a15e17c76e0b58fd3e09a1f13 to your computer and use it in GitHub Desktop.
Make cross-faded seamless loop video from non-loop video
# Based on https://stackoverflow.com/questions/60043174/cross-fade-video-to-itself-with-ffmpeg-for-seamless-looping
# and conversations with ChatGPT
duration=$(ffprobe -v error -show_entries format=duration -of noprint_wrappers=1:nokey=1 input.mp4)
duration=$(echo "$duration - 2" | bc)
ffmpeg -i input.mp4 -filter_complex "[0]trim=end=1,setpts=PTS-STARTPTS,fps=fps=30[begin];[0]trim=start=1,setpts=PTS-STARTPTS,fps=fps=30[end];[end][begin]xfade=fade:duration=1:offset=${duration}" output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment