Guest User

Untitled

a guest
Nov 8th, 2019
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import sys
  2. from time import sleep
  3. import cv2 as cv
  4.  
  5. # Using nvv4l2h264enc
  6. out_gst_pipe = 'appsrc ! queue ! videoconvert ! video/x-raw,format=(string)BGRx ! nvvidconv ! video/x-raw(memory:NVMM),format=(string)NV12 ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=testvid1.mp4'
  7.  
  8. # Using nvv4l2h264enc and matroskamux
  9. # out_gst_pipe = 'appsrc ! queue ! videoconvert ! video/x-raw,format=(string)BGRx ! nvvidconv ! video/x-raw(memory:NVMM),format=(string)NV12 ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=testvid2.mkv'
  10.  
  11. # Using omxh264enc
  12. # out_gst_pipe = "appsrc ! videoconvert ! omxh264enc profile=2 preset-level=1 control-rate=2 bitrate=10000000 ! video/x-h264, streamformat=(string)byte-stream ! h264parse ! qtmux ! filesink location=testvid3.mp4"
  13.  
  14. cc = cv.VideoWriter_fourcc(*'mp4v')
  15. out = cv.VideoWriter(out_gst_pipe, cv.CAP_GSTREAMER, cc, 21, (1280, 960))
  16.  
  17. if not out.isOpened():
  18.     out.release()
  19.     print('shucks')
  20.     sys.exit(1)
  21.  
  22.  
  23. pipe = 'nvarguscamerasrc sensor-id=0 maxperf=1 ! video/x-raw(memory:NVMM),format=(string)NV12,width=(int)3280,height=(int)2464,framerate=(fraction)21/1 ! nvvidconv flip-method=2 ! video/x-raw,width=(int)1280,height=(int)960,format=(string)BGRx ! videoconvert ! video/x-raw,format=(string)BGR ! appsink'
  24. cap = cv.VideoCapture(pipe, cv.CAP_GSTREAMER)
  25. if not cap.isOpened():
  26.     cap.release()
  27.     out.release()
  28.     print('oh, come on...')
  29.     sys.exit(2)
  30.  
  31.  
  32. for i in range(21 * 20):
  33.     ret, frame = cap.read()
  34.     if not ret:
  35.         print('no read')
  36.         break
  37.     cv.imshow('frame', frame)
  38.     cv.waitKey(1)
  39.     out.write(frame)
  40.  
  41. cv.destroyAllWindows()
  42. out.release()
  43. cap.release()
Advertisement
Add Comment
Please, Sign In to add comment