Sensors & Effectors/Camera

[OpenCV][Python] Save video

jstar0525 2021. 7. 12. 19:31
반응형
import os
import cv2
from pathlib import Path
from datetime import datetime

path = Path('/home/ubuntu/data/')
path.mkdir(parents=True, exist_ok=True)
src = '/dev/video0'
W, H, fps = 1920, 1080, 6

cap = cv2.VideoCapture(src)
fourcc = cv2.VideoWriter_fourcc('H','2','6','4')
cap.set(3, W)
cap.set(4, H)
cap.set(5, fps)
cap.set(6, fourcc)

t = datetime.now().strftime('%Y-%m-%d_%H-%M-%S_%f')
f_name = os.path.join(path, t)
out = cv2.VideoWriter(f_name+'.avi', fourcc, fps, (W,H))

while(True):
    ret, frame = cap.read()

    if ret:
        out.write(frame)
        cv2.imshow('frame', cv2.resize(frame, dsize=(860, 540)))

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

 

 

 

 

Set video format in jetson

ENV : Jetson AGX Xavier with JetPack 4.5.1 (Ubuntu 18.04)

$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=1920,height=1080,framerate=6/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink

https://jstar0525.tistory.com/102

 

[Camera] Check Camera format, resolution and fps

Install v4l-utils $ sudo apt-get install v4l-utils Supports Camera format $ v4l2-ctl --list-formats ioctl: VIDIOC_ENUM_FMT Index : 0 Type : Video Capture Pixel Format: 'MJPG' (compressed) Name : Mot..

jstar0525.tistory.com

https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/accelerated_gstreamer.html#wwpID0E0XZ0HA

 

Tegra Linux Driver

Your browser has DOM storage disabled. Make sure DOM storage is enabled and try again.

docs.nvidia.com

 

반응형