|
28 | 28 | import picamera2.utils as utils |
29 | 29 | from picamera2.allocators import DmaAllocator |
30 | 30 | from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality |
31 | | -from picamera2.outputs import FfmpegOutput, FileOutput |
| 31 | +from picamera2.outputs import FileOutput, PyavOutput |
32 | 32 | from picamera2.previews import DrmPreview, NullPreview, QtGlPreview, QtPreview |
33 | 33 |
|
34 | 34 | from .configuration import CameraConfiguration |
@@ -2596,26 +2596,36 @@ def start_and_record_video(self, output, encoder=None, config=None, quality=Qual |
2596 | 2596 | example by calling stop_recording). |
2597 | 2597 |
|
2598 | 2598 | audio - whether to record audio. This is only effective when recording to an "mp4" or "ts" |
2599 | | - file, and there is a microphone installed and working as the default input device |
2600 | | - through Pulseaudio. |
| 2599 | + file, and there is a microphone installed and working as the default input device. |
2601 | 2600 | """ |
2602 | 2601 | if self.started: |
2603 | 2602 | self.stop() |
2604 | 2603 | if not self.camera_config and config is None: |
2605 | 2604 | config = "video" |
2606 | 2605 | if config is not None: |
2607 | 2606 | self.configure(config) |
| 2607 | + |
2608 | 2608 | if isinstance(output, str): |
2609 | | - if encoder is None: |
2610 | | - extension = output.split('.')[-1].lower() |
2611 | | - if extension in ("mjpg", "mjpeg"): |
| 2609 | + extension = output.split('.')[-1].lower() |
| 2610 | + if extension in ("mjpg", "mjpeg"): |
| 2611 | + if audio: |
| 2612 | + raise ValueError("Audio not supported in MJPEG flies") |
| 2613 | + if encoder is None: |
2612 | 2614 | encoder = MJPEGEncoder() |
2613 | | - if extension in ("mp4", "ts"): |
2614 | | - output = FfmpegOutput(output, audio=audio) |
2615 | | - else: |
2616 | | - output = FileOutput(output) |
| 2615 | + output = PyavOutput(output) |
| 2616 | + elif extension in ("mp4", "ts"): |
| 2617 | + if encoder is None: |
| 2618 | + encoder = H264Encoder() |
| 2619 | + output = PyavOutput(output) |
| 2620 | + else: |
| 2621 | + if audio: |
| 2622 | + raise ValueError("Audio not supported in output " + output) |
| 2623 | + output = FileOutput(output) |
| 2624 | + |
2617 | 2625 | if encoder is None: |
2618 | 2626 | encoder = H264Encoder() |
| 2627 | + encoder.audio = audio |
| 2628 | + |
2619 | 2629 | self.start_encoder(encoder=encoder, output=output, quality=quality) |
2620 | 2630 | self.start(show_preview=show_preview) |
2621 | 2631 | if duration: |
|
0 commit comments