Several bugfixes - bitreich-tv - Meme TV encoding and streaming
 (HTM) git clone git://bitreich.org/bitreich-tv git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/bitreich-tv
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) LICENSE
       ---
 (DIR) commit 9955fec4d21435eae1aa98c8c7078932d192df5c
 (DIR) parent 3a8559a5c96734befbfdb580c7e8a2ab491ea6d4
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Tue, 11 Aug 2020 21:26:32 +0200
       
       Several bugfixes
       
       Diffstat:
         M brtv-start.sh                       |      51 ++++++++++++++++++++-----------
       
       1 file changed, 33 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/brtv-start.sh b/brtv-start.sh
       @@ -1,12 +1,6 @@
        #!/bin/sh
       -# generate title animations and start streaming server
       -
       -pass="$(gpg2 -q -d icecastpass.gpg)"
       -
       -if [ $# -ne 1 ]; then
       -        printf 'usage: %s <memecache_path>\n' "$0" >&2
       -        exit
       -fi
       +# generate title animations and start streaming to server
       +# requirements: ffmpeg(1), convert(1)
        
        ### CONFIGURATION START
        
       @@ -44,6 +38,20 @@ title_display_time=5
        
        ### CONFIGURATION END
        
       +pass="$(gpg2 -q -d icecastpass.gpg)"
       +
       +die() {
       +        printf '%s: error: %s\n' "${0##*/}" "$1" >&2
       +        exit 1
       +}
       +
       +regeximatch() {
       +        printf '%s' "$1" | grep -iEq "$2"
       +}
       +
       +if [ $# -ne 1 ]; then
       +        die "usage: ${0##*/} <memecache_path>"
       +fi
        
        fit_img_16_9() {
                convert -resize "$video_resolution"\> -size "$video_resolution" "$1" \
       @@ -62,6 +70,7 @@ video_from_img() {
        
        title_slide() {
                img="$(basename "${1%.*}".png)"
       +        #echo "title_slide $1 -> $img"
                convert -size "$video_resolution" "xc:${bgcolor}" \
                        -pointsize 48 -fill "$fgcolor" \
                        -gravity center -draw "text 0,0 '#${img%.*}'" "$img"
       @@ -70,21 +79,28 @@ title_slide() {
                        -i anullsrc=r=48000 \
                        -i "$img" \
                        -t "${title_display_time}" \
       -                $ffmpec_codec \
       +                $ffmpeg_codec \
                        "$2" && rm "$img"
        }
        
        video_conv() {
       -        ffmpeg -y -i "$1" $ffmpeg_codec -max_muxing_queue_size 1024 "$2"
       +        printf 'encode %s -> %s\n' "$1" "$2"; ffmpeg -y -i "$1" $ffmpeg_codec -max_muxing_queue_size 1024 "$2"
        }
        
        mkdir -p "$title"
        mkdir -p "$memecache_conv"
        
        # generate video from each image
       -for f in "$memecache"/*.{jpg,jpeg,JPG,png,PNG}; do
       +for f in "$memecache"/*.jpg \
       +        "$memecache"/*.jpeg \
       +        "$memecache"/*.JPG \
       +        "$memecache"/*.png \
       +        "$memecache"/*.PNG; do
                out="${memecache_conv}/$(basename "${f%.*}.${video_ext}")"
       -        if [ -e "$f" ] && [ ! -e "$out" ]; then
       +        if [ ! -f "$out" ]; then
       +                if ! regeximatch "$(file -ib "$f")" "^image\/"; then
       +                        die "input image $f is invalid ($(file -b "$f"))"
       +                fi
                        printf 'in: %s, out: %s\n' "$f" "$out"
                        fit_img_16_9 "$f" "${out%.*}.jpg"
                        video_from_img "${out%.${video_ext}}.jpg" "${out}"
       @@ -96,18 +112,17 @@ if [ ! -f "bitreich-tv.${video_ext}" ]; then
                title_slide bitreich-tv bitreich-tv.${video_ext}
        fi
        
       -
       -# make title slides for video and converted images and encode to common codec
       +# make title slides for video and converted images and encode all video clips to common codec
        for f in "$memecache"/*.mkv \
                 "$memecache"/*.mp4 \
                         "$memecache"/*.webm \
                         "$memecache_conv"/*."${video_ext}"; do
        
       -        title_path="${title}/$(basename "${f%.*}.webm")"
       -        [ ! -e "$title_path" ] && title_slide "$f" "$title_path"
       +        title_path="${title}/$(basename "${f%.*}.${video_ext}")"
       +        [ ! -f "$title_path" ] && title_slide "$f" "$title_path"
        
       -        out="${memecache_conv}/$(basename "${f%.*}.webm")"
       -        [ ! -e "$out" ] && video_conv "$f" "$out"
       +        out="${memecache_conv}/$(basename "${f%.*}.${video_ext}")"
       +        [ ! -f "$out" ] && video_conv "$f" "$out"
        done
        
        # generate random playlist from converted memes and add title slides