Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
streaming a still image with ability to replace it on the fly
FROM alpine
LABEL maintainer="Victor Maslov <nakilon@gmail.com>"
# usage example 1:
# cp some_image_1.png image.png
# docker run -d -v $(pwd):/mounted -w /mounted --log-driver none -e key=... nakilonishe/ffmpeg-stream-image
# cp some_image_2.png image.png
# cp some_image_3.png image.png
# usage example 2:
# docker build . -t ${PWD##*/} < ffmpeg-stream-image.Dockerfile
# export key=...
# docker run -it -v $(pwd):/mounted -w /mounted --log-driver local --rm -e key -e loglevel=info -e s=426x240 -e preset=ultrafast ${PWD##*/}
RUN apk add ffmpeg
ENV loglevel=warning s=640x360 preset=medium
# https://support.google.com/youtube/answer/2853702?hl=en
# https://trac.ffmpeg.org/wiki/Encode/H.264
CMD sh -c "ffmpeg -loglevel $loglevel -re -framerate 30 -stream_loop -1 -f image2 -i image.png -f lavfi -i anullsrc -s $s -c:v libx264 -preset $preset -tune stillimage -g 150 -c:a aac -b:a 8k -f flv 'rtmp://a.rtmp.youtube.com/live2/$key'"

Streaming local Moscow time:

  • mkdir stream && cd stream
  • test run:
    docker run --rm -it -v $(pwd):/mounted -w /mounted --log-driver local -e TZ=Europe/Moscow nakilonishe/alpine-vips-text sh -c "apk add tzdata && while sleep 0.5; do vips text image.v \"\$(date '+%Y-%m-%d%n %H:%M:%S')\" --dpi 200 --font Monospace && vips invert image.v atomic.png && mv atomic.png image.png; done"
    export key=...
    docker run --rm -it -v $(pwd):/mounted -w /mounted --log-driver local -e key -e loglevel=info -e s=640x360 -e preset=medium nakilonishe/ffmpeg-stream-image
  • check htop, bitrate, tweak preset and s if needed:
  • final run:
    docker run --rm -d -v $(pwd):/mounted -w /mounted --log-driver none -e TZ=Europe/Moscow nakilonishe/alpine-vips-text sh -c "apk add tzdata && while sleep 0.5; do vips text image.v \"\$(date '+%Y-%m-%d%n %H:%M:%S')\" --dpi 200 --font Monospace && vips invert image.v atomic.png && mv atomic.png image.png; done"
    docker run --rm -d -v $(pwd):/mounted -w /mounted --log-driver none -e key -e loglevel=quiet nakilonishe/ffmpeg-stream-image

https://www.youtube.com/watch?v=I6iJzdK1JsI

FROM alpine
LABEL maintainer="Victor Maslov <nakilon@gmail.com>"
# building example:
# docker build --build-arg VIPS_VERSION=8.9.1 -t alpine-vips-text - < vips-text.Dockerfile
ARG VIPS_VERSION=8.6.4
RUN set -x -o pipefail \
&& wget -O- https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz | tar xzC /tmp \
&& apk add glib libpng orc pango \
&& apk add --virtual vips-dependencies \
build-base libpng-dev orc-dev \
pango-dev msttcorefonts-installer \
&& cd /tmp/vips-${VIPS_VERSION} \
&& ./configure --prefix=/usr \
--disable-static \
--disable-debug \
--disable-dependency-tracking \
--enable-silent-rules \
&& make -s install-strip \
&& update-ms-fonts \
&& cd $OLDPWD \
&& rm -rf /tmp/vips-${VIPS_VERSION} \
&& apk del --purge vips-dependencies \
&& rm -rf /var/cache/apk/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment