Hi,
I am trying to send camera feed as opencv frames through udp port and receive the frames and save it as a video, below is the Producer program and Receiver program that I am using,
Producer.py
import cv2
from multiprocessing import Process
def savefile():
cap_feed = cv2.VideoCapture('nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink',cv2.CAP_GSTREAMER)
frame_width = int(cap_feed.get(3))
frame_height = int(cap_feed.get(4))
size = (frame_width, frame_height)
cap_send = cv2.VideoWriter('appsrc ! videoconvert ! x264enc tune = zerolatency bitrate = 500 ! rtph264pay ! udpsink host = 127.0.0.1 port = 5000',cv2.CAP_GSTREAMER, 0, 20, size, True)
if not cap_feed.isOpened():
print('VideoCapture not opened')
exit(0)
while True:
ret, frame = cap_feed.read()
if not ret:
print('empty frame')
break
cap_send.write(frame)
cap_feed.release()
cap_send.release()
if __name__ == '__main__':
savefile()
Receiver.py
import cv2
from multiprocessing import Process
import time
def receive_n_save():
cap_receive = cv2.VideoCapture('udpsrc port = 5000 caps = "application/x-rtp, media = (string)video, clock-rate = (int)90000, encoding-name = (string)H264, payload = (int)96" ! rtph264depay ! decodebin ! videoconvert ! appsink',cv2.CAP_GSTREAMER)
if not cap_receive.isOpened():
print('receive_n_save : Sending not opened')
exit(0)
frame_width = int(cap_receive.get(3))
frame_height = int(cap_receive.get(4))
size = (frame_width, frame_height)
print(cap_receive, size)
# Below VideoWriter object will create a frame of above defined The output is stored in 'feed_filename_fourcc_codec.avi' file.
result = cv2.VideoWriter('PIM1'+int(time.time())+'.avi',
cv2.VideoWriter_fourcc(*'PIM1'), #available options : MJPG, PIM1 etc.
20, size)
while True:
ret, frame = cap_receive.read()
if not ret:
print('empty frame')
break
else:
# Write the frame into the file 'feed_filename_fourcc_codec.avi'
result.write(frame)
cap_receive.release()
if __name__ == '__main__':
receive_n_save()
the following is the error message that I get trying to run these programs,
Error message in Receiver.py
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
NVMEDIA: NVMEDIABufferProcessing: 1507: NvMediaParserParse Unsupported Codec
do anyone know how to solve this issue?