URI: 
       Fix title and image viewing duration, create fallback stream - bitreich-memestats - Bitreich meme statistics and graphs.
  HTML git clone git://bitreich.org/bitreich-memestats git://hg6vgqziawt5s4dj.onion/bitreich-memestats
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR LICENSE
       ---
   DIR commit 3c3d3a067be47f9db268d4817d937a49ecf5f051
   DIR parent 9a39dea48b13099733de2f6ff98de64901702b09
  HTML Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Thu, 11 Jun 2020 13:42:37 +0000
       
       Fix title and image viewing duration, create fallback stream
       
       Diffstat:
         M brtv-start.sh                       |     100 ++++++++++++++++++-------------
       
       1 file changed, 57 insertions(+), 43 deletions(-)
       ---
   DIR diff --git a/brtv-start.sh b/brtv-start.sh
       @@ -1,6 +1,5 @@
        #!/bin/sh
       -# start streaming server, but beforehand reencode memecache and
       -# generate title animations if necessary
       +# generate title animations and start streaming server
        
        if [ $# -ne 1 ]; then
                printf 'usage: %s <memecache_path>\n' "$0" >&2
       @@ -9,24 +8,23 @@ fi
        
        ### CONFIGURATION START
        
       -# mkv streaming server executable
       -# git://github.com/klaxa/mkvserver_mk2
       -bin=mkvserver_mk2
       +# streaming server executable
       +#bin=vlc
       +
       +# intermediate playlist file
       +playlist="playlist"
        
        # memecache source dir
        memecache="$1"
        
        # converted memecache dir
       -memecache_conv=memecache
       +memecache_conv="memecache"
        
        # title animations dir
        title="title"
        
       -# desired ffmpeg codec flags
       -ffmpeg_codec="-c:v libx264 -c:a libvorbis -f matroska"
       -
       -# port for streaming socket (combined stream hosted on port 8080)
       -commport=12345
       +# ffmpeg codec flags for generated animations
       +ffmpeg_codec="-acodec libopus -b:a 96K -vcodec libvpx -f webm -vf scale=1280:-1 -r 30 -ac 2"
        
        # target video resolution
        video_resolution=1280x720
       @@ -35,11 +33,11 @@ video_resolution=1280x720
        bgcolor=magenta
        fcolor=white
        
       -# show image memes for this duration [s]
       +# show image memes for this duration, must be two digits [s]
        image_display_time=10
        
       -# show title slides for this duration [s]
       -title_display_time=5
       +# show title slides for this duration, must be two digits [s]
       +title_display_time=05
        
        ### CONFIGURATION END
        
       @@ -54,73 +52,89 @@ video_from_img() {
                        -f lavfi \
                        -i anullsrc=r=48000 \
                        -i "$1" \
       -                -t "00:${3}:00" \
       +                -t "00:00:${image_display_time}" \
                        $ffmpeg_codec \
                        "$2";
        }
        
        title_slide() {
                img="$(basename "${1%.*}".png)"
       -        convert -size "$video_resolution" "xc:${bgcolor}" -pointsize 48 -fill "$fgcolor" \
       +        convert -size "$video_resolution" "xc:${bgcolor}" \
       +                -pointsize 48 -fill "$fgcolor" \
                        -gravity center -draw "text 0,0 '#${img%.*}'" "$img"
                ffmpeg -y \
                        -f lavfi \
                        -i anullsrc=r=48000 \
                        -i "$img" \
       -                -t "00:${title_display_time}:00" \
       +                -t "00:00:${title_display_time}" \
                        $ffmpec_codec \
       -                "$2";
       +                "$2" && rm "$img"
        }
        
        video_conv() {
       -        ffmpeg -y -i "$1" $ffmpeg_codec "$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 "$memecache"/*.png "$memecache"/*.JPG; do
       -        out="${memecache_conv}/$(basename "${f%.*}.mkv")"
       -        if [ ! -e "$out" ]; then
       +for f in "$memecache"/*.jpg "$memecache"/*.JPG "$memecache"/*.png "$memecache"/*.PNG; do
       +        out="${memecache_conv}/$(basename "${f%.*}.webm")"
       +        if [ -e "$f" ] && [ ! -e "$out" ]; then
       +                printf 'in: %s, out: %s\n' "$f" "$out"
                        fit_img_16_9 "$f" "${out%.*}.jpg"
       -                video_from_img "${out%.mkv}.jpg" "${out}" "${image_display_time}"
       +                video_from_img "${out%.webm}.jpg" "${out}"
                fi
        done
        
       +# make animation for fallback stream
       +if [ ! -f bitreich-tv.webm ]; then
       +        title_slide bitreich-tv bitreich-tv.webm
       +fi
       +
       +
        # make title slides for video and converted images and encode to common codec
        for f in "$memecache"/*.mkv \
                 "$memecache"/*.mp4 \
                         "$memecache"/*.webm \
       -                 "$memecache_conv"/*.mkv; do
       +                 "$memecache_conv"/*.webm; do
        
       -        title_path="${title}/$(basename "${f%.*}.mkv")"
       -        [ ! -e "${title_path}" ] && title_slide "$f" "$title_path"
       +        title_path="${title}/$(basename "${f%.*}.webm")"
       +        [ ! -e "$title_path" ] && title_slide "$f" "$title_path"
        
       -        out="${memecache_conv}/$(basename "${f%.*}.mkv")"
       -        [ ! -e "${out}" ] && video_conv "$f" "$out"
       +        out="${memecache_conv}/$(basename "${f%.*}.webm")"
       +        [ ! -e "$out" ] && video_conv "$f" "$out"
        done
        
        # generate random playlist from converted memes and add title slides
       -find "$memecache_conv" -maxdepth 1 -name "*.mkv" -type f | sort -R | \
       -        sed "s/^/file '/;s/$/'/" | \
       -        awk -v titledir="$title" '
       +find "$memecache_conv" -maxdepth 1 -name "*.webm" -type f | \
       +        sort -R | \
       +        awk -v memecachedir="$memecache" -v titledir="$title" '
                function add_title(s) {
       -                sub(/\.\//, titledir"/", s);
       +                sub(/memecache/, "title", s);
                        return s
                }
                {line=$0;
       -        print add_title($line);
       -        print $0}' > playlist
       +        print "file \""add_title($line)"\"";
       +        print "file \""$0"\""}' | sed "s/\"/'/g" > "$playlist"
       +        #print "file \""$0"\""}' | sed "s/\"/'/g" |grep -v title> "$playlist"
       +
       +printf '\nstarting fallback stream\n'
       +ffmpeg -loglevel quiet \
       +        -stream_loop -1 -i bitreich-tv.webm
       +        -f webm -codec copy
       +        icecast://source:hasselkospiserkrymmel@localhost:8000/brtvfallback
       +
       +exit 0
        
       -netcat -l -p "$commport" | $bin >/dev/null 2>&1 &
       -sleep 2
       +sleep 5
        
       -ffmpeg -f concat -safe 0 -i playlist \
       -        -f matroska \
       -        $ffmpeg_codec \
       -        -max_muxing_queue_size 9999 \
       -        tcp://localhost:$commport
       +printf '\nstarting stream\n'
        
       -pkill $bin
       +ffmpeg -f concat -safe 0 -stream_loop -1 -i "$playlist" \
       +        -f webm -cluster_size_limit 2M -cluster_time_limit 5100 -content_type video/webm \
       +        -analyzeduration 2M -probesize 2M \
       +        -codec copy \
       +        -deadline realtime -threads 8 \
       +        icecast://source:hasselkospiserkrymmel@localhost:8000/brtv