import cv2
import numpy as np
# Replace with your H.265 video file
gst_pipeline = (
"filesrc location=/home/ninja/test1.mp4 ! "
"qtdemux ! h265parse ! nvv4l2decoder ! "
"nvvidconv ! video/x-raw,width=1920,height=1080,format=NV12 ! "
"appsink"
)
cap = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)
h = 1080
w = 1920
if not cap.isOpened():
print("Failed to open video")
exit()
while True:
ret, frame = cap.read()
if not ret:
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)
#cv2.imshow("Jetson H.265 Video", frame)
#if cv2.waitKey(1) & 0xFF == ord("q"):
# break
cap.release()
cv2.destroyAllWindows()