Allow images and videos in new deface filter. - 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 a7b6271d25d1e871de322f700ab5fc352b87b4ed
(DIR) parent 8178121cf184328ccf2dbd37f7ff2b97d1cfd08c
(HTM) Author: Annna Robert-Houdin <annna@bitreich.org>
Date: Sun, 7 Aug 2022 01:00:32 +0200
Allow images and videos in new deface filter.
Diffstat:
M annna-message-common | 44 ++++++++++++++++++++++---------
M ffmpeg-effect | 207 ++++++++++++++++++-------------
2 files changed, 149 insertions(+), 102 deletions(-)
---
(DIR) diff --git a/annna-message-common b/annna-message-common
@@ -889,6 +889,28 @@ case "${text}" in
[ ! -f "${inpath}" ] && exit 0
+ # outfile and outpath filtering for the cache.
+ case "${filter}" in
+ antidepressant)
+ outfile="${outfile%.*}.jpg"
+ outpath="${outpath%.*}.jpg"
+ ;;
+ putin)
+ outfile="${outfile%.*}.jpg"
+ outpath="${outpath%.*}.jpg"
+ ;;
+ wat|smith|zucc)
+ mimetype="$(file --mime-type "$inpath" | cut -d':' -f 2 | cut -c 2-)"
+ # Only allow images to be free.
+ case "$mimetype" in
+ image/*)
+ outfile="${outfile%.*}.${origext}"
+ outpath="${outpath%.*}.${origext}"
+ ;;
+ esac
+ esac
+
+ # Cleanup if outpath file is empty.
[ -f "${outpath}" -a ! -s "${outpath}" ] && rm "${outpath}"
if [ -s "${outpath}" ];
@@ -898,19 +920,15 @@ case "${text}" in
fi
case "${filter}" in
- antidepressant)
- outfile="${outfile%.*}.jpg"
- outpath="${outpath%.*}.jpg"
- antidepressant "${inpath}" "${outpath}" 2>&1 >/dev/null
- ;;
- putin)
- outfile="${outfile%.*}.jpg"
- outpath="${outpath%.*}.jpg"
- putin-os "${inpath}" "${outpath}" 2>&1 >/dev/null
- ;;
- *)
- ffmpeg-effect "${filter}" "${inpath}" "${outpath}" 2>&1 >/dev/null
- ;;
+ antidepressant)
+ antidepressant "${inpath}" "${outpath}" 2>&1 >/dev/null
+ ;;
+ putin)
+ putin-os "${inpath}" "${outpath}" 2>&1 >/dev/null
+ ;;
+ *)
+ ffmpeg-effect "${filter}" "${inpath}" "${outpath}" 2>&1 >/dev/null
+ ;;
esac
if [ "${recipient}" != "${text}" ];
(DIR) diff --git a/ffmpeg-effect b/ffmpeg-effect
@@ -12,6 +12,17 @@ usage() {
exit 1
}
+is_image() {
+ mimetype="$(file --mime-type "$1" | cut -d':' -f 2 | cut -c 2-)"
+ case "${mimetype}" in
+ image/*)
+ return 0
+ ;;
+ esac
+
+ return 1
+}
+
has_audio() {
ffprobe "$1" 2>&1 | grep -qE 'Stream .* Audio: '
}
@@ -63,13 +74,19 @@ mix_audio_video() {
}
replace_face() {
+ set -x
+
face_replacement="$1"
input="$2"
output="$3"
- #ext="$(printf '%s' "$input" | awk -F. '{print $NF}')"
- #tmp=/tmp/replace_face_$$.$ext
- tmp="/tmp/replace_face_$$.mkv"
+ if is_image $input;
+ then
+ ext="$(printf '%s' "$input" | awk -F. '{print $NF}')"
+ tmp=/tmp/replace_face_$$.$ext
+ else
+ tmp="/tmp/replace_face_$$.mkv"
+ fi
$HOME/.local/bin/deface "$input" --replacewith img \
--replaceimg "$face_replacement" -o "$tmp" >/dev/null 2>&1
@@ -80,9 +97,27 @@ replace_face() {
else
mv "$tmp" "$output"
fi
+
+ set +x
}
process_filter() {
+ # Filters which do not require image2mkv.
+ case "$1" in
+ wat)
+ replace_face "${mediadir}/wat.png" "$2" "$3"
+ return 0
+ ;;
+ smith)
+ replace_face "${mediadir}/smith.png" "$2" "$3"
+ return 0
+ ;;
+ zucc)
+ replace_face "${mediadir}/zucc.png" "$2" "$3"
+ return 0
+ ;;
+ esac
+
# extend duration if less than a second or image
dur="$($ffprobe_common -show_entries format=duration "$2")"
if test "$dur" = "N/A" || test "${dur%.*}" -lt 1; then
@@ -93,92 +128,86 @@ process_filter() {
fi
case "$1" in
- amplify)
- $ffmpeg_common -i "$2" -filter:a "volume=10" "$3";;
- banjo)
- replace_audio "${mediadir}/banjo.mp3" "$2" "$3";;
- bounce)
- $ffmpeg_common -i "$2" \
- -filter_complex "[0]reverse[r];[0][r]concat,loop=${repeats}:250,setpts=N/25/TB" -an \
- "$3" </dev/null;;
- celtify)
- mix_audio "${mediadir}/broceliande.ogg" "$2" "$3";;
- concatenate)
- mix_audio "${mediadir}/concatenate.mp3" "$2" "$3";;
- daybowbow)
- replace_audio "${mediadir}/day-bow-bow.ogg" "$2" "$3";;
- dontdoit)
- mix_audio "${mediadir}/dontdoit.mp3" "$2" "$3";;
- doomify)
- mix_audio "${mediadir}/doom.mp3" "$2" "$3";;
- dutchapprove)
- mix_audio_video "${mediadir}/krul.mkv" "$2" "$3" 524 480;;
- imam)
- mix_audio "${mediadir}/imam.mp3" "$2" "$3";;
- 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;;
- mow)
- mix_audio "${mediadir}/lawn-mower.mp3" "$2" "$3";;
- reverse)
- $ffmpeg_common -i "$2" \
- -vf reverse -af areverse \
- "$3" </dev/null;;
- science)
- replace_audio "${mediadir}/accelerating-science.mp3" "$2" "$3";;
- scrollify)
- mix_audio "${mediadir}/elder_scrolls.mp3" "$2" "$3";;
- sendtohell|amsterdamify)
- mix_audio_video "${mediadir}/hell.mkv" "$2" "$3" 1920 1080;;
- sexify)
- mix_audio "${mediadir}/careless_whisper.mp3" "$2" "$3";;
- slavify)
- replace_audio "${mediadir}/remove-kebab.opus" "$2" "$3";;
- 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;;
- smith)
- replace_face "${mediadir}/smith.png" "$2" "$3";;
- 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;;
- techno)
- replace_audio "${mediadir}/techno.mp3" "$2" "$3";;
- technodrugs)
- $ffmpeg_common -i "${mediadir}/techno.mp3" -i "$2" \
- -filter:v "tmix=frames=9:weights='0.2 0.4 0.6 0.8 1 0.8 0.6 0.4 0.2'" \
- -map 1:v:0 -map 0:a:0 -shortest \
- "$3" </dev/null;;
- thin)
- $ffmpeg_common -i "$2" \
- -vf "scale=iw/4:ih,setsar=1" \
- "$3" </dev/null;;
- torture)
- side_by_side "${mediadir}/clockworkorange.mkv" "$2" "$3";;
- trumpapprove)
- mix_audio "${mediadir}/trump-approves.opus" "$2" "$3";;
- wat)
- replace_face "${mediadir}/wat.png" "$2" "$3";;
- wide|widen)
- $ffmpeg_common -i "$2" \
- -vf "scale=iw*4:ih,crop=iw/4:ih:iw/4:ih,setsar=1" \
- "$3" </dev/null;;
- ww1)
- mix_audio "${mediadir}/ww1.mp3" "$2" "$3";;
- yellow)
- mix_audio "${mediadir}/yellow.opus" "$2" "$3";;
- zucc)
- replace_face "${mediadir}/zucc.png" "$2" "$3";;
- *) usage;;
+ amplify)
+ $ffmpeg_common -i "$2" -filter:a "volume=10" "$3";;
+ banjo)
+ replace_audio "${mediadir}/banjo.mp3" "$2" "$3";;
+ bounce)
+ $ffmpeg_common -i "$2" \
+ -filter_complex "[0]reverse[r];[0][r]concat,loop=${repeats}:250,setpts=N/25/TB" -an \
+ "$3" </dev/null;;
+ celtify)
+ mix_audio "${mediadir}/broceliande.ogg" "$2" "$3";;
+ concatenate)
+ mix_audio "${mediadir}/concatenate.mp3" "$2" "$3";;
+ daybowbow)
+ replace_audio "${mediadir}/day-bow-bow.ogg" "$2" "$3";;
+ dontdoit)
+ mix_audio "${mediadir}/dontdoit.mp3" "$2" "$3";;
+ doomify)
+ mix_audio "${mediadir}/doom.mp3" "$2" "$3";;
+ dutchapprove)
+ mix_audio_video "${mediadir}/krul.mkv" "$2" "$3" 524 480;;
+ imam)
+ mix_audio "${mediadir}/imam.mp3" "$2" "$3";;
+ 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;;
+ mow)
+ mix_audio "${mediadir}/lawn-mower.mp3" "$2" "$3";;
+ reverse)
+ $ffmpeg_common -i "$2" \
+ -vf reverse -af areverse \
+ "$3" </dev/null;;
+ science)
+ replace_audio "${mediadir}/accelerating-science.mp3" "$2" "$3";;
+ scrollify)
+ mix_audio "${mediadir}/elder_scrolls.mp3" "$2" "$3";;
+ sendtohell|amsterdamify)
+ mix_audio_video "${mediadir}/hell.mkv" "$2" "$3" 1920 1080;;
+ sexify)
+ mix_audio "${mediadir}/careless_whisper.mp3" "$2" "$3";;
+ slavify)
+ replace_audio "${mediadir}/remove-kebab.opus" "$2" "$3";;
+ 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;;
+ 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;;
+ techno)
+ replace_audio "${mediadir}/techno.mp3" "$2" "$3";;
+ technodrugs)
+ $ffmpeg_common -i "${mediadir}/techno.mp3" -i "$2" \
+ -filter:v "tmix=frames=9:weights='0.2 0.4 0.6 0.8 1 0.8 0.6 0.4 0.2'" \
+ -map 1:v:0 -map 0:a:0 -shortest \
+ "$3" </dev/null;;
+ thin)
+ $ffmpeg_common -i "$2" \
+ -vf "scale=iw/4:ih,setsar=1" \
+ "$3" </dev/null;;
+ torture)
+ side_by_side "${mediadir}/clockworkorange.mkv" "$2" "$3";;
+ trumpapprove)
+ mix_audio "${mediadir}/trump-approves.opus" "$2" "$3";;
+ wide|widen)
+ $ffmpeg_common -i "$2" \
+ -vf "scale=iw*4:ih,crop=iw/4:ih:iw/4:ih,setsar=1" \
+ "$3" </dev/null;;
+ ww1)
+ mix_audio "${mediadir}/ww1.mp3" "$2" "$3";;
+ yellow)
+ mix_audio "${mediadir}/yellow.opus" "$2" "$3";;
+ *) usage;;
esac
}