Monday 27 November 2023

How to check if a port is opening?

$ nc -zv 192.168.1.123 4440
Connection to 192.168.1.123 4440 port [tcp/*] succeeded!
$ nc -zv 192.168.1.123 1234
^C

Thursday 16 November 2023

How to write a video using gstreamer with opencv

import numpy as np
import cv2, os
gstcmd = "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" #cap = cv2.VideoCapture(gstcmd, cv2.CAP_GSTREAMER) cap = cv2.VideoCapture(gstcmd) count = 0 h = 1080 w = 1920 gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! nvvideoconvert ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=/data/test.mp4" out= cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(60), (int(1920), int(1080))) while(True): try: count += 1 # Capture frame-by-frame ret, frame = cap.read() if ret == False: break #frame = np.fromstring(frame, dtype=np.uint8).reshape((int(h*3/2),w,1)) #frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV12) print(frame.shape) out.write(frame) # Display the resulting frame #cv2.imshow('frame',frame) #if cv2.waitKey(1) & 0xFF == ord('q'): # break except: try: cap = cv2.VideoCapture(gstcmd, cv2.CAP_GSTREAMER) except: print("rtsp connection is down %d..." % (count)) # When everything done, release the capture cap.release() cv2.destroyAllWindows()