Hi all,
I got a usb camera connected to my Jetson TX2 and I’m using opencv to read frames from the usb camera and then push the frames to a remote server using ffmpeg and rmtp protocol. The codes works and I can read the rtmp stream on another desktop. But when reading the stream, there is a big lag and the fps is so low (metadata says fps is 5). I tried to execute the same code on my desktop and then check the result, the result is good, high fps with a neglectable lag. When pushing the stream, TX2 uses only 1/4 of the bitrates compared to the desktop.
This is the code for pushing the stream:
import cv2
import subprocess as sp
rtmpUrl = 'rtmp://xxxxxxxxxxxxxxxxxx'
cap = cv2.VideoCapture(1)
if cap.isOpened():
print('camera opened')
else:
print('Fail to open camera')
cap.set(3, 640)
cap.set(4, 480)
sizeStr = str(640) + 'x' + str(480)
fps = int(cap.get(cv2.CAP_PROP_FPS))
command = ['ffmpeg',
'-y',
'-an',
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-pix_fmt', 'bgr24',
'-s', sizeStr,
'-r', str(fps),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-f', 'flv',
rtmpUrl]
pipe = sp.Popen(command, stdin=sp.PIPE)
while True:
ret, frame = cap.read()
if not ret:
break
else:
pipe.stdin.write(frame.tostring())
And the terminal command for viewing the stream:
ffplay -fflags nobuffer rtmp://xxxxxxxxxxxxxxxxxxxxxxxx
Any suggestions?