Created
February 25, 2018 14:29
-
-
Save packer-/8daa8d12a61fb870688c8457b4ab5fe5 to your computer and use it in GitHub Desktop.
ffmpeg
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/bash | |
set -eu pipefail | |
# -------------------------------------------------------------------------------------------------- | |
# ffmpeg functions | |
# https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos | |
# 2 games... | |
ffmpeg_2() { | |
ffmpeg \ | |
-i layout-test.png \ | |
-i nicks/"${clip_nick[0]}"-scaled.png \ | |
-i nicks/"${clip_nick[1]}"-scaled.png \ | |
-i maps/"${clip_map[0]}.png" \ | |
-i clips/"${clip[0]}" \ | |
-i clips/"${clip[1]}" \ | |
-i nicks/"${clip_nick[2]}"-scaled.png \ | |
-i nicks/"${clip_nick[3]}"-scaled.png \ | |
-i maps/"${clip_map[2]}.png" \ | |
-i clips/"${clip[2]}" \ | |
-i clips/"${clip[3]}" \ | |
-filter_complex " | |
nullsrc=size=1920x1080[v0base]; | |
[4:v] setpts=PTS-STARTPTS, scale=1128:847, fade=in:0:$fadein_t,fade=out:${game_fadeout_at[0]}:$fadeout_t [v0l]; | |
[5:v] setpts=PTS-STARTPTS, scale=744:559, fade=in:0:$fadein_t,fade=out:${game_fadeout_at[0]}:$fadeout_t [v0r]; | |
[v0base][v0l] overlay=shortest=1: x=16:y=193 [v0-1]; | |
[v0-1] [v0r] overlay=shortest=1:x=1160:y=193 [v0-2]; | |
[v0-2] [3:v] overlay=1576:767 [v0-3]; | |
[v0-3] [0:v] overlay=0:0 [v0-4]; | |
[v0-4] [1:v] overlay=436:145 [v0-5]; | |
[v0-5] [2:v] overlay=1388:145 [v0]; | |
[4:a] volume=enable='between(t,0,2.95)':volume=0 [a0-1]; | |
[a0-1] afade=t=in:ss=2.95:d=0.05 [a0]; | |
nullsrc=size=1920x1080[v1base]; | |
[9:v] setpts=PTS-STARTPTS, scale=1128:847, fade=in:0:$fadein_t,fade=out:${game_fadeout_at[1]}:$fadeout_t [v1l]; | |
[10:v] setpts=PTS-STARTPTS, scale=744:559, fade=in:0:$fadein_t,fade=out:${game_fadeout_at[1]}:$fadeout_t [v1r]; | |
[v1base][v1l] overlay=shortest=1: x=16:y=193 [v1-1]; | |
[v1-1] [v1r] overlay=shortest=1:x=1160:y=193 [v1-2]; | |
[v1-2] [8:v] overlay=1576:767 [v1-3]; | |
[v1-3] [0:v] overlay=0:0 [v1-4]; | |
[v1-4] [6:v] overlay=436:145 [v1-5]; | |
[v1-5] [7:v] overlay=1388:145 [v1]; | |
[9:a] volume=enable='between(t,0,2.95)':volume=0 [a1-1]; | |
[a1-1] afade=t=in:ss=2.95:d=0.05 [a1]; | |
[v0][a0][v1][a1] concat=n=2:v=1:a=1 [v][a]" \ | |
-map "[v]" -map "[a]" \ | |
-preset slow -c:v h264_nvenc -b:v 2000k -profile:v high -coder 1 -pix_fmt yuv420p -flags +cgop \ | |
-r 60 -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low \ | |
-movflags +faststart \ | |
final/"$match_id".mp4 | |
} | |
# -------------------------------------------------------------------------------------------------- | |
fadein_t=$((3*60)) | |
fadeout_t=$((3*60)) | |
sed 's/"\([0-9]*\),\([0-9]*\)"/\1\.\2/g' demolist_sorted.csv > /tmp/fewqfhre | |
for match_id in $(find clips/ -type f -name '*.mp4' | sort -n | cut -d/ -f2 | cut -d\- -f1 | sort -u); do | |
echo "match: $match_id" | |
[ -f final/$match_id.mp4 ] && continue | |
unset clips | |
i=0 | |
for mp4 in $(find clips/ -type f -name "$match_id"'*.mp4' | sort -n | cut -d/ -f2 | sort -u); do | |
clip[i]="$mp4" | |
clip_frames[i]=$(ffprobe -select_streams v -show_streams "clips/$mp4" 2>/dev/null | grep nb_frames | cut -d\= -f2) | |
clip_name="${mp4%\.mp4}" | |
clip_nick[i]="$(grep ${clip_name//-/,} /tmp/fewqfhre | cut -d, -f12)" | |
clip_map[i]="$(grep ${clip_name//-/,} /tmp/fewqfhre | cut -d, -f13)" | |
echo "$i > ${clip[i]}, frames: ${clip_frames[i]}, nick: ${clip_nick[i]}" | |
((++i)) | |
done | |
games=$(("${#clip[@]}/2")) | |
echo "clips: ${#clip[@]}, games=$games" | |
for i in $(seq 0 $((games-1))); do | |
left=$((i*2)) | |
right=$((left+1)) | |
if [[ $(echo "${clip_frames[left]} > ${clip_frames[right]}" | bc -l ) == 0 ]]; then | |
game_frames[i]=${clip_frames[left]} | |
else | |
game_frames[i]=${clip_frames[right]} | |
fi | |
game_fadeout_at[i]=$(echo "${game_frames[i]} - $fadeout_t" | bc -l) | |
echo "game $i: - l: $left, r: $right - frames: ${game_frames[i]}, fade out at: ${game_fadeout_at[i]}" | |
done | |
case $games in | |
2) ffmpeg_2; continue;; | |
3) exit;; | |
4) exit;; | |
5) exit;; | |
6) exit;; | |
7) exit;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment