Skip to content

Commit d2e50ad

Browse files
committed
Allow the base Encoder() to accept raw and other stream types
But only if the output supports completely arbitrary formats. Also add the existing capture_video_raw.py to test_list.txt so that we don't break this again. Signed-off-by: David Plowman <[email protected]>
1 parent e623daa commit d2e50ad

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

picamera2/encoders/encoder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ def _start(self):
304304
"RGB888": "bgr24",
305305
"XBGR8888": "rgba",
306306
"XRGB8888": "bgra"}
307-
pix_fmt = FORMAT_TABLE[self._format]
307+
pix_fmt = FORMAT_TABLE.get(self._format)
308308
rate = Fraction(1000000, self._framerate)
309309
for out in self._output:
310+
if pix_fmt is None and out.needs_add_stream:
311+
raise RuntimeError(f"Output does not support {self._format}")
310312
out._add_stream("video", "rawvideo", pix_fmt=pix_fmt, rate=rate,
311313
width=self.width, height=self.height)
312314

picamera2/outputs/output.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, pts=None):
1313
self.recording = False
1414
self.ptsoutput = pts
1515
self.needs_pacing = False
16+
self.needs_add_stream = False
1617

1718
def start(self):
1819
"""Start recording"""

picamera2/outputs/pyavoutput.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, output_name, format=None, pts=None, options=None):
2727
self._options = options
2828
# A user can set this to get notifications of failures.
2929
self.error_callback = None
30+
self.needs_add_stream = True
3031

3132
def _add_stream(self, encoder_stream, codec_name, **kwargs):
3233
# The output container that does the muxing needs to know about the streams for which packets

picamera2/outputs/splittableoutput.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, output=None, *args, **kwargs):
1919
self._new_output = None
2020
self._split_done = Event()
2121
self._streams = []
22+
self.needs_add_stream = True
2223

2324
def split_output(self, new_output, wait_for_keyframe=True):
2425
"""

tests/test_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ examples/capture_to_buffer.py
1212
examples/capture_video.py
1313
examples/capture_video_multiple.py
1414
examples/capture_video_multiple_2.py
15+
examples/capture_video_raw.py
1516
examples/controls.py
1617
examples/controls_2.py
1718
examples/display_transform_qtgl.py

0 commit comments

Comments
 (0)