Created
November 24, 2018 16:07
-
-
Save knzm/d9e0fa5c9af6a3ad49df348c0f035b4d to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
set -eu | |
input=$1 | |
output=$2 | |
time=$3 | |
fade_out_duration=0.5 | |
fade_in_duration=0.5 | |
fade_out_offset=0.5 | |
fade_in_offset=0.5 | |
afade_out_duration=0.5 | |
afade_in_duration=0.5 | |
afade_out_offset=0 | |
afade_in_offset=0 | |
fade_out_start_time=$( | |
echo "${time} - ${fade_out_duration} - ${fade_out_offset}" | bc | |
) | |
fade_in_start_time=${fade_in_offset} | |
afade_out_start_time=$( | |
echo "${time} - ${afade_out_duration} - ${afade_out_offset}" | bc | |
) | |
afade_in_start_time=${afade_in_offset} | |
filter_graph="\ | |
[0:v] split=2 [vcopy1][vcopy2]; \ | |
[vcopy1] trim=end=${time},setpts=PTS-STARTPTS [vpart1], \ | |
[vcopy2] trim=start=${time},setpts=PTS-STARTPTS [vpart2], \ | |
[vpart1] fade=t=out:st=${fade_out_start_time}:d=${fade_out_duration} [vout1], \ | |
[vpart2] fade=t=in:st=${fade_in_start_time}:d=${fade_in_duration} [vout2]; \ | |
[vout1][vout2] concat=n=2:v=1:a=0 [vout]; \ | |
[0:a] asplit=2 [acopy1][acopy2]; \ | |
[acopy1] atrim=end=${time},asetpts=PTS-STARTPTS [apart1], \ | |
[acopy2] atrim=start=${time},asetpts=PTS-STARTPTS [apart2], \ | |
[apart1] afade=t=out:st=${afade_out_start_time}:d=${afade_out_duration} [aout1], \ | |
[apart2] afade=t=in:st=${afade_in_start_time}:d=${afade_in_duration} [aout2]; \ | |
[aout1][aout2] concat=n=2:v=0:a=1 [aout]\ | |
" | |
ffmpeg \ | |
-threads 0 \ | |
-loglevel warning \ | |
-stats \ | |
-y \ | |
-i "${input}" \ | |
-vsync passthrough \ | |
-filter_complex "${filter_graph}" \ | |
-map "[vout]" \ | |
-map "[aout]" \ | |
"${output}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment