Close

Working on Video

A project log for Analog TV Broadcast of the new Age

How to broadcast colored PAL television with a SDR transmitter.

marblemarble 09/15/2018 at 23:220 Comments

Being able to transmit a still image is already quite fun, but of course I also want to be able to do moving picture.

The algorithm that implements the generation of a still images was purely implemented in python. Although python is a nice langue, it's not very fast without any external help.

I was thinking abut using numpy for matrix manipulation, but then I found out that ffmpeg can encode into raw YUV (aka Y Cb Cr) values.

ffmpeg -i /home/marble/lib/Videos/bigbuckbunny.mp4 \
-c:v rawvideo \
-vf 'scale=702:576:force_original_aspect_ratio=decrease,pad=702:576:(ow-iw)/2:(oh-ih)/2' \
-f rawvideo \
-pix_fmt yuv444p \
-r 50 \
-

This command not only transforms any video into a raw YUV stream and writes it to stdout, it also sets the frame rate to 50 fps, scales the video down to PAL resolution and applies letterboxing. For each video frame ffmpeg output a whole Y frame, then a U frame and then a V frame.

I tried to the the rest purely in gnuradio-companion, but as it turnes out, this would be really hard and quite a mess. So I turned back to python for the adding of synchronization pulses etc.

To use ffmpeg in python I use the subprocess module.

#!/usr/bin/env python3
import subprocess
VISIB_LINES     = 576
PIXEL_PER_LINE  = 702
VIDEO_SCALE     = '{}:{}'.format(PIXEL_PER_LINE, VISIB_LINES)
ffmpeg = subprocess.Popen(['/usr/bin/ffmpeg',
    '-i', '/home/marble/lib/Videos/bigbuckbunny.mp4',
    '-c:v', 'rawvideo',
    '-vf', 'scale=' + VIDEO_SCALE + ':force_original_aspect_ratio=decrease,pad=' + VIDEO_SCALE + ':(ow-iw)/2:(oh-ih)/2',
    '-c:v', 'rawvideo',
    '-f', 'rawvideo',
    '-pix_fmt', 'yuv444p',
    '-r', '50',
    '-loglevel', 'quiet',
    #    '-y',
    '-'],
    stdout = subprocess.PIPE) 

Discussions