0

I would like to create the pipeline like the image below;

https://i.stack.imgur.com/Nb17P.png

GSTREAMER_OUT = ' ! '.join([
        'appsrc',
        'queue',
        f'video/x-raw,format=BGR,width={frame_width},height={frame_height}',
        'videoconvert',
        'video/x-raw,format=YV12',
        'x264enc byte-stream=true',
        'video/x-h264,stream-format=avc,alignment=au,profile=baseline',
        ' '.join([
            'kvssink',
            f'stream-name={kvs_out_stream_name}',
            'storage-size=512',
            f'access-key={access_key}',
            f'secret-key={secret_key}',
            'aws-region=ap-northeast-1',
            # 'buffer-duration=60',
            f'framerate=1',
            # 'max-latency=10',
        ]),
    ])

cap = cv2.VideoCapture(in_stream_url)
out = cv2.VideoWriter(GSTREAMER_OUT, cv2.CAP_GSTREAMER, 0, target_fps, (frame_width, frame_height), True)

while True:
    ret, frame = cap.read()
    result = some_image_process(frame)
    out.write(result)

However, the management console often shows broken frames like below;

https://i.stack.imgur.com/oecrR.png

whole video: https://youtu.be/vBAgECHYJjU

I would like to know how to fix this GStreamer pipeline. I am not so familiar with Gstreamer so it would be appreciated if you tell the GStreamer pipeline in detail.

LittleWat
  • 53
  • 6

1 Answers1

0

I found this is fixed when I remove queue and add options to x264enc like the command below;

GSTREAMER_OUT = ' ! '.join([
    'appsrc',
    'clockoverlay halignment=right valignment=top font-desc="Sans bold 60px"',
    'videoconvert',
    'video/x-raw,format=YV12',
    'x264enc byte-stream=true noise-reduction=10000 speed-preset=ultrafast tune=zerolatency ',
    'video/x-h264,stream-format=avc,alignment=au,profile=baseline',
    ' '.join([
        'kvssink',
        f'stream-name={kvs_out_stream_name}',
        'storage-size=512',
        f'access-key={access_key}',
        f'secret-key={secret_key}',
        'aws-region=ap-northeast-1',
        # 'buffer-duration=10',
        # 'connection-staleness=60',
        # "fragment-acks=true",
        "framerate=1",
        # "key-frame-fragmentation=false",
        # "max-latency=10"
    ]),
])

longer sample code: https://gist.github.com/LittleWat/c93394bb4f6dc125d1c4a66f1a7aee9d

the broken image was fixed but there is a problem of latency.

So I will ask another question. How to reduce the gstreamer pipeline latency in "AWS Kinesis Video Stream(kvs) -> gstreamer+opencv image processing -> kvs " process?

LittleWat
  • 53
  • 6