Playing with YUV colour space from command line

I wanted to get familiar with the YUV colour space, and the direction of U/V axes used in common video formats.

A bash one-liner made it easy for me to input colour values and preview them:

while true; do read -p "Y: " y && read -p "U: " u && read -p "V: " v && perl -e "print '$y' x 4096; print '$u' x 1024; print '$v' x 1024;" | xxd -r -ps | ffplay -f rawvideo -pix_fmt yuv420p -s 64x64 - ; done

Breaking this ad-hoc one-liner down into parts:

#!/bin/bash

set -e

echo "Enter Y/U/V values as two-char hex-byte value e.g. 3f"

# Loop until user hits Ctrl+C
while true
do

  # Read colour co-ordinates
  read -p "Y: " y
  read -p "U: " u
  read -p "V: " v

  # Generate hex of a 64x64-pixel image frame in YUV420p encoding, un-hex it, display it on screen with FFMPEG
  perl -e "print '$y' x 4096; print '$u' x 1024; print '$v' x 1024;" | \
    xxd -r -ps | \
    ffplay -f rawvideo -pix_fmt yuv420p -s 64x64 -

done

Great 🙂