Introduction
Introduction Statistics Contact Development Disclaimer Help
tPut image->video processing into separate script - bitreich-tv - meme tv encod…
git clone git://src.adamsgaard.dk/bitreich-tv
Log
Files
Refs
---
commit 469296142ed571c3e38749a234a9eb31205645ac
parent 9712aec3da3a8dd8e17f8626c138ae12c26e9c8c
Author: Anders Damsgaard <[email protected]>
Date: Sun, 16 Aug 2020 21:33:26 +0200
Put image->video processing into separate script
Diffstat:
A brtv-imgs-to-video.sh | 78 +++++++++++++++++++++++++++++…
1 file changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/brtv-imgs-to-video.sh b/brtv-imgs-to-video.sh
t@@ -0,0 +1,78 @@
+#!/bin/sh
+# read hashtags.txt as stdin, download all images, and convert them to videos
+# requirements: hurl(1), ffmpeg(1), convert(1)
+
+
+### CONFIGURATION START
+
+# dir to contain images as videos
+out_dir="img2vid"
+
+# ffmpeg flags for generated videos
+video_ext="webm"
+ffmpeg_codec="-loglevel error -acodec libopus -b:a 96K -vcodec libvpx -b:v 64k…
+
+# target video resolution
+video_resolution=1280x720
+
+# slide style
+bgcolor=magenta
+
+# show image memes for this duration [s]
+image_display_time=10
+
+### CONFIGURATION END
+
+
+die() {
+ printf '%s: error: %s\n' "${0##*/}" "$1" >&2
+ exit 1
+}
+
+regeximatch() {
+ printf '%s' "$1" | grep -iEq "$2"
+}
+
+fit_img_16_9() {
+ convert -resize "$video_resolution"\> -size "$video_resolution" "$1" \
+ xc:"$bgcolor" +swap -gravity center -composite "$2"
+}
+
+video_from_img() {
+ ffmpeg -y \
+ -f lavfi \
+ -i anullsrc=r=48000 \
+ -i "$1" \
+ -t "${image_display_time}" \
+ $ffmpeg_codec \
+ "$2" < /dev/null
+}
+
+mkdir -p "$out_dir"
+
+# generate video from each image
+# TODO: deal with .gif
+while read -r tag url; do
+ if ! regeximatch "$url" '\.(jpg|jpeg|png)$'; then
+ continue
+ fi
+
+ imgfile="${out_dir}/${url##*/}"
+ out="${imgfile%.*}.${video_ext}"
+
+ if [ ! -f "$out" ]; then
+
+ if [ ! -f "$imgfile" ]; then
+ if ! hurl "$url" > "$imgfile"; then
+ die "hurl could not download $url"
+ fi
+ fi
+
+ if ! regeximatch "$(file -ib "$imgfile")" "^image\/"; then
+ die "input image $imgfile is invalid ($(file -b "$imgf…
+ fi
+ fit_img_16_9 "$imgfile" "${out%.*}_16-9.jpg"
+ video_from_img "${out%.${video_ext}}_16-9.jpg" "${out}"
+ printf '%s\n' "$out"
+ fi
+done
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.