Forked from coderofsalvation/crossfadevideo.sh
Last active
December 21, 2020 21:53
-
-
Save victoriagrace/27c40ac6f2aa3076410dea7b8b0afb90 to your computer and use it in GitHub Desktop.
ffmpeg commandline crossfade-looped video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed duration calculation typo