#!/usr/bin/env python
import os
import sys

gen_cmd = "gst-launch-1.0 videotestsrc num-buffers=292 pattern=smpte ! video/x-raw\,\ format\=\(string\)NV12\,\ width\=\(int\)1920\,\ height\=\(int\)1080\,\ framerate\=\(fraction\)30/1 ! filesink location=/tmp/buf.raw"

os.system(gen_cmd)

cmd = "gst-launch-1.0 -f filesrc location=/tmp/buf.raw blocksize=3110400 ! videoparse width=1920 height=1080 framerate=30 format=nv12 ! tee name=encoder ! queue name=enc_1 max-size-buffers=1 ! vaapih264enc rate-control=2 bitrate=20000 keyframe-period=30 ! fakesink encoder. ! queue name=enc_2 max-size-buffers=1 ! vaapih264enc rate-control=2 bitrate=20000 keyframe-period=30 ! fakesink encoder. ! queue name=enc_3 max-size-buffers=1 ! vaapih264enc rate-control=2 bitrate=20000 keyframe-period=30 ! fakesink encoder. ! queue name=enc_4 max-size-buffers=1 ! vaapih264enc rate-control=2 bitrate=20000 keyframe-period=30 ! fakesink"

while True:
    retcode = os.system(cmd)
    if retcode != 0:
        sys.exit()
