FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
depthai-python/examples/VideoEncoder/rgb_encoding.py at main · moratom/depthai-python · GitHub
moratom
depthai-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
depthai-python
/
examples
/
VideoEncoder
/
rgb_encoding.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
42 lines (32 loc) · 1.47 KB
Breadcrumbs
depthai-python
/
examples
/
VideoEncoder
/
rgb_encoding.py
Copy path
File metadata and controls
executable file
·
42 lines (32 loc) · 1.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import
depthai
as
dai
# Create pipeline
pipeline
=
dai
.
Pipeline
()
# Define sources and output
camRgb
=
pipeline
.
create
(
dai
.
node
.
ColorCamera
)
videoEnc
=
pipeline
.
create
(
dai
.
node
.
VideoEncoder
)
xout
=
pipeline
.
create
(
dai
.
node
.
XLinkOut
)
xout
.
setStreamName
(
'h265'
)
# Properties
camRgb
.
setBoardSocket
(
dai
.
CameraBoardSocket
.
RGB
)
camRgb
.
setResolution
(
dai
.
ColorCameraProperties
.
SensorResolution
.
THE_4_K
)
videoEnc
.
setDefaultProfilePreset
(
30
,
dai
.
VideoEncoderProperties
.
Profile
.
H265_MAIN
)
# Linking
camRgb
.
video
.
link
(
videoEnc
.
input
)
videoEnc
.
bitstream
.
link
(
xout
.
input
)
# Connect to device and start pipeline
with
dai
.
Device
(
pipeline
)
as
device
:
# Output queue will be used to get the encoded data from the output defined above
q
=
device
.
getOutputQueue
(
name
=
"h265"
,
maxSize
=
30
,
blocking
=
True
)
# The .h265 file is a raw stream file (not playable yet)
with
open
(
'video.h265'
,
'wb'
)
as
videoFile
:
print
(
"Press Ctrl+C to stop encoding..."
)
try
:
while
True
:
h265Packet
=
q
.
get
()
# Blocking call, will wait until a new data has arrived
h265Packet
.
getData
().
tofile
(
videoFile
)
# Appends the packet data to the opened file
except
KeyboardInterrupt
:
# Keyboard interrupt (Ctrl + C) detected
pass
print
(
"To view the encoded data, convert the stream file (.h265) into a video file (.mp4) using a command below:"
)
print
(
"ffmpeg -framerate 30 -i video.h265 -c copy video.mp4"
)
Back
|
FazBrowse Home
|
New Git URL