Converting Data to QR Code Video

One of the things I enjoy about computing is trying something silly, just to see what happens. Ever wonder what a live well of rainbow trout looks like as a QR code video? Well, look no further!


The tools involved are QREncode, ImageMagick, and MPlayer.

#!/bin/env bash

export PREFIX

cat $1 | base64 -w 0| split -a 4 -b 2048 - ${PREFIX}.

for file in ${PREFIX}.????
  echo Converting $file...
  cat $file | qrencode -s 4 -o - | convert - ${file}.jpg

mencoder                                \
  mf://${PREFIX}*.jpg -mf fps=30        \
  -ovc x264                             \
  -x264encopts "threads=auto:crf=30:me=umh:me_range=16:subq=2:trellis=0:global_header:level_idc=41:force_cfr"           \
  -o output.mp4

echo Cleaning up...
rm ${PREFIX}.???? ${PREFIX}.????.jpg

Clearly you are wondering why I chose to break up the source file into smaller files 2048 bytes in size? According to the QR Code Wikipedia page, the maximum binary data a QR code can hold is 2,953 bytes. The qrencode utility sqawked with some byte sizes above 2048, so picking a nice binary number seems to play well.

The resulting video file looks like:

The real question is can we fetch sane data from the video file? The answer is yes, and more tools, zbar, and FFMpeg.

The decoding script looks something like:


export PREFIX

ffmpeg -i $1 -r 30 ${PREFIX}-%06d.jpg

for x in ${PREFIX}-??????.jpg
  zbarimg -q --raw $x
done | base64 -d - > DATA

Put this under the “why computers are fun” file.

Comments are closed.