add more video meme filters and split into separate script - annna - Annna the nice friendly bot.
(HTM) git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
(DIR) commit 63e3baa4192174b82f3376aebd2a9b13c6949ac7
(DIR) parent 8f1461a7105aabe20dfed0162b5f967fccc12a10
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 18 May 2021 21:52:21 +0200
add more video meme filters and split into separate script
Signed-off-by: Annna Robert-Houdin <annna@bitreich.org>
Diffstat:
M annna-message-common | 20 ++++++++++++--------
A ffmpeg-effect | 76 +++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 8 deletions(-)
---
(DIR) diff --git a/annna-message-common b/annna-message-common
@@ -652,16 +652,20 @@ case "${text}" in
"${botname}, bonjour !")
annna-say -c "${channel}" "${user}, bonjour !"
;;
-"${botname}, please widen #"*)
- hashtag="$(printf "%s\n" "${text}" | cut -c 22-)"
+"${botname}, please widen #"*|\
+"${botname}, please thin #"*|\
+"${botname}, please speedup #"*|\
+"${botname}, please slowdown #"*|\
+"${botname}, please reverse #"*|\
+"${botname}, please loop #"*|\
+"${botname}, please bounce #"*)
+ hashtag="$(printf "%s\n" "${text}" | sed 's/.*#//' )"
origext="$(grep -E "^#${hashtag} " "${hashtagfile}" | sed 's/.*\.//')"
- widefile="wide-${hashtag}.mkv"
{
- if ffmpeg -n -i "/br/gopher/memecache/${hashtag}.${origext}" \
- -vf "scale=iw*4:ih,crop=iw/4:ih:iw/4:ih,setsar=1" \
- "/br/gopher/memecache/wide/${widefile}"
- then
- annna-say -c "${channel}" "${user}, gopher://bitreich.org/9/memecache/wide/${widefile}"
+ filter="$(printf '%s\n' "${text}" | cut -d' ' -f3)"
+ if outfile="$(ffmpeg-effect "$filter" "/br/gopher/memecache/${hashtag}.${origext}")"; then
+ mv "$outfile" "/br/gopher/memecache/filter/${outfile}" && \
+ annna-say -c "${channel}" "${user}, gopher://bitreich.org/9/memecache/filter/${outfile}"
fi
} &
exit 0
(DIR) diff --git a/ffmpeg-effect b/ffmpeg-effect
@@ -0,0 +1,76 @@
+#!/bin/sh
+# modify a video input file with an effect.
+# output is saved as "./filter-filename.mkv".
+# requirements: ffmpeg.
+
+ffmpeg_common="ffmpeg -n -loglevel error"
+
+repeats=5
+usage() {
+ printf 'usage: %s [-n REPEATS] FILTER file\n' "${0##*/}" 1>&2
+ printf 'where FILTER is one of: wide, thin, speedup, ' 1>&2
+ printf 'slowdown, reverse, loop, bounce.\n' 1>&2
+ printf 'For loop and bounce, option -n sets the number of repeats (default %d).\n' "$repeats" 1>&2
+ exit 1
+}
+
+process_filter() {
+ case "$1" in
+ wide|widen)
+ $ffmpeg_common -i "$2" \
+ -vf "scale=iw*4:ih,crop=iw/4:ih:iw/4:ih,setsar=1" \
+ "$3" </dev/null;;
+ thin)
+ $ffmpeg_common -i "$2" \
+ -vf "scale=iw/4:ih,setsar=1" \
+ "$3" </dev/null;;
+ speedup)
+ $ffmpeg_common -i "$2" \
+ -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" \
+ "$3" </dev/null;;
+ slowdown)
+ $ffmpeg_common -i "$2" \
+ -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" \
+ "$3" </dev/null;;
+ reverse)
+ $ffmpeg_common -i "$2" \
+ -vf reverse -af areverse \
+ "$3" </dev/null;;
+ loop)
+ i=0
+ input=""
+ while test $i -lt $repeats; do
+ input="$input -i $2"
+ i=$((i + 1))
+ done
+ $ffmpeg_common $input \
+ -filter_complex "concat=n=${repeats}:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" \
+ "$3" </dev/null;;
+ bounce)
+ $ffmpeg_common -i "$2" \
+ -filter_complex "[0]reverse[r];[0][r]concat,loop=${repeats}:250,setpts=N/25/TB" -an \
+ "$3" </dev/null;;
+ *) usage;;
+ esac
+}
+
+while getopts 'hn:' opt; do
+ case $opt in
+ h) usage;;
+ n) n="$OPTARG";;
+ *) break;;
+ esac
+done
+shift $((OPTIND - 1))
+if test "$#" -lt 2 -o ! -r "$2"; then
+ usage
+fi
+
+n=$((n - 1))
+base="$(basename "$2")"
+out="${1}-${base%.*}.mkv"
+if process_filter "$1" "$2" "$out"; then
+ printf '%s\n' "$out"
+else
+ exit $?
+fi