Skip to content

Instantly share code, notes, and snippets.

@micolous
Last active January 15, 2020 11:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micolous/ba93b3833a3957e56377c0c592868a89 to your computer and use it in GitHub Desktop.
Save micolous/ba93b3833a3957e56377c0c592868a89 to your computer and use it in GitHub Desktop.
"Does anyone know how to use xrandr" glitch slides using ffmpeg. #lca2020
#!/bin/bash
# "Does anyone know how to use xrandr" glitch slides using ffmpeg. #lca2020
# Author: Michael Farrell <micolous+git@gmail.com>
# License: BSD-2-Clause or CC-0 (your choice).
#
######
#
# For linux.conf.au in Gold Coast, Ruan (@xfxf) asked me to make a simple "smoosh / defrag"
# slide that would be displayed as a holding slide between talks. I made some others with some
# AV team "in-jokes"... :)
#
# On the third day of the conference (2020-01-15), the video generated by this script was shown
# on-screen: https://twitter.com/glasnt/status/1217220463924928513
#
# This uses a title slide, "lca2020-xrandr-720p.png", which is displayed normally for 7 seconds,
# then "glitches" for 2 seconds, and then returns to normal for 7 seconds. It is intended to be
# run in a loop.
#
# If you wonder "what is xrandr?" -- it's a command-line tool for Xorg (graphics/display server)
# that lets you adjust display settings. It's a very powerful tool with a lot of options; but
# most Linux desktop environments' display settings dialog make it very easy to "just" enable
# a second display in mirroring or extending modes. :)
#
######
#
# Create the "normal" title slide segment from PNG, running for 7 seconds (xrandr-regular-7s.ts)
ffmpeg -loop 1 -i lca2020-xrandr-720p.png -t 7 \
-codec:v mpeg2video -b:v 5000k xrandr-regular-7s.ts
# Create the "glitched" title slide segment from PNG, running for 2 seconds (xrandr-broken-2s.ts)
# This adds noise every 1000 bytes of the (video) bitstream:
# Docs: https://ffmpeg.org/ffmpeg-bitstream-filters.html#noise
ffmpeg -loop 1 -i lca2020-xrandr-720p.png -t 2 \
-codec:v mpeg2video -bsf:v noise=1000 -b:v 5000k xrandr-broken-2s.ts
# Stitch the files back together, and re-encode (xrandr-partial.ts)
# We need to re-encode because the behaviour of glitched bitstream is unpredictable between players.
ffmpeg -f concat -safe 0 \
-i <(for f in xrandr-regular-7s.ts xrandr-broken-2s.ts xrandr-regular-7s.ts; do echo "file '$PWD/$f'"; done) \
-b:v 5000k xrandr-partial.ts
# That file was called "partial" because my first version of this was _entirely_ glitched.
# But that was just unreadable. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment