0

I'm trying to stream video to AWS Kinesis Video Streams using OpenCV and GStreamer, but I'm having trouble getting it to work. I have set up a Kinesis video stream with the name ExampleStream, and I want to use a numpy array as the source of the video frames.

Here's the code I'm using:

import cv2
import numpy as np
import time
from Utils.utils import get_aws_cred

access_key, secret_key, region = get_aws_cred()

pipeline = (
    f"appsrc ! videoconvert ! video/x-raw,format=BGR,width={400},height={400},framerate=25/1 ! videoconvert ! video/x-raw ! x264enc key-int-max=45 ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! kvssink stream-name=ExampleStream storage-size=512 aws-region={region} access-key={access_key} secret-key={secret_key}  max-latency=1 buffer-duration=1"
)

out = cv2.VideoWriter(pipeline, cv2.CAP_GSTREAMER, 0, float(25), (400, 400), True)

while True:
    frame = (np.random.rand(400, 400, 3) * 255).astype(np.uint8)
    out.write(frame)
    time.sleep(0.04)

There is no error or something I can debug to figure it out. Also when I am running a pipeline from my terminal its works, so I assume that the configuration in the aws is correct. The pipeline I am running through the terminal is:

"gst-launch-1.0 videotestsrc is-live=true ! video/x-raw,framerate=25/1 ! videoconvert ! x264enc  bframes=0 key-int-max=45 bitrate=500 ! video/x-h264,stream-format=avc,alignment=au,profile=baseline ! kvssink stream-name=ExampleStream storage-size=512 access-key=$AWS_ACCESS_KEY_ID secret-key=$AWS_SECRET_ACCESS_KEY aws-region=$AWS_REGION max-latency=1 buffer-duration=1"

any idea what's wrong with the pipeline or how to debug it?

HiRod
  • 11
  • 3
  • I'd suspect the framerate to be wrong in VideoWriter. Try replacing '1' by `float(25)` if your opencv app processes 25 fps. – SeB Feb 20 '23 at 19:03
  • The 25 fps was set only to the GStreamer pipeline, which I ran from the command line using "gst-launch-1.0". For better clarity, I have updated the code to match the command line pipeline. But it's still not working. – HiRod Feb 26 '23 at 13:09

0 Answers0