Skip to content

Instantly share code, notes, and snippets.

@victoriagrace
Forked from coderofsalvation/crossfadevideo.sh
Last active December 21, 2020 21:53
Show Gist options
  • Save victoriagrace/27c40ac6f2aa3076410dea7b8b0afb90 to your computer and use it in GitHub Desktop.
Save victoriagrace/27c40ac6f2aa3076410dea7b8b0afb90 to your computer and use it in GitHub Desktop.
ffmpeg commandline crossfade-looped video
#!/bin/bash
[[ ! -n $3 ]] && { echo "Usage: crossfadevideo <input.mp4> <fade in seconds> <output.mp4>"; exit; }
input="$1"
fade="$2"
duration="$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 $1 )"
duration="$(echo "$duration-($fade)" | bc)"
[[ ${duration:0:1} == "." ]] && duration="0$duration"
output="$3"
set -x
ffmpeg -i "$input" -filter_complex '
[0]split[body][pre];
[pre]trim=duration='$fade',format=yuva420p,fade=d='$fade':alpha=1,setpts=PTS+('$duration'/TB)[jt];
[body]trim='$fade',setpts=PTS-STARTPTS[main];
[main][jt]overlay' "$output"
@victoriagrace
Copy link
Author

Fixed duration calculation typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment