Skip to content

Commit 87d7bc5

Browse files
committed
Allow libav H264 encoder to use V4L2 hardware on VC4 platforms
This also provides a route to using the PyavOutput. Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
1 parent 1786285 commit 87d7bc5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

picamera2/encoders/libav_h264_encoder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import av
88

9+
import picamera2.platform as Platform
910
from picamera2.encoders.encoder import Encoder, Quality
1011

1112
from ..request import MappedArray
@@ -28,6 +29,22 @@ def __init__(self, bitrate=None, repeat=True, iperiod=30, framerate=30, qp=None,
2829
self.drop_final_frames = False
2930
self.threads = 0 # means "you choose"
3031
self._lasttimestamp = None
32+
self._use_hw = False
33+
34+
@property
35+
def use_hw(self):
36+
"""Whether hardware encode will be used (can be set to True only for VC4 platforms)."""
37+
return self._use_hw
38+
39+
@use_hw.setter
40+
def use_hw(self, value):
41+
"""Set this property in order to get libav to use the V4L2 hardware encoder (VC4 platforms only)."""
42+
if value:
43+
if Platform.get_platform() == Platform.Platform.VC4:
44+
self._use_hw = True
45+
self._codec = "h264_v4l2m2m"
46+
else:
47+
print("Warning: use_hw has no effect on non-VC4 platforms")
3148

3249
def _setup(self, quality):
3350
# If an explicit quality was specified, use it, otherwise try to preserve any bitrate/qp

0 commit comments

Comments
 (0)