RGB Encoding
Similar samples:
- RGB & Mono Encoding
- Encoding Max Limit
- # RGB Encoding & MobilenetSSD
- # RGB Encoding & Mono & MobilenetSSD
- # RGB Encoding & Mono with MobilenetSSD & Depth
Demo
Setup
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.pySource code
Python
C++
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import depthai as dai
4
5# Create pipeline
6pipeline = dai.Pipeline()
7
8# Define sources and output
9camRgb = pipeline.create(dai.node.ColorCamera)
10videoEnc = pipeline.create(dai.node.VideoEncoder)
11xout = pipeline.create(dai.node.XLinkOut)
12
13xout.setStreamName('h265')
14
15# Properties
16camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
17camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
18videoEnc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.H265_MAIN)
19
20# Linking
21camRgb.video.link(videoEnc.input)
22videoEnc.bitstream.link(xout.input)
23
24# Connect to device and start pipeline
25with dai.Device(pipeline) as device:
26
27 # Output queue will be used to get the encoded data from the output defined above
28 q = device.getOutputQueue(name="h265", maxSize=30, blocking=True)
29
30 # The .h265 file is a raw stream file (not playable yet)
31 with open('video.h265', 'wb') as videoFile:
32 print("Press Ctrl+C to stop encoding...")
33 try:
34 while True:
35 h265Packet = q.get() # Blocking call, will wait until a new data has arrived
36 h265Packet.getData().tofile(videoFile) # Appends the packet data to the opened file
37 except KeyboardInterrupt:
38 # Keyboard interrupt (Ctrl + C) detected
39 pass
40
41 print("To view the encoded data, convert the stream file (.h265) into a video file (.mp4) using a command below:")
42 print("ffmpeg -framerate 30 -i video.h265 -c copy video.mp4")Pipeline
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.