Skip to content

Commit a52e4a2

Browse files
committed
Make start_and_capture_video use PyavOutput instead of FfmpegOutput
This is the recommended way of doing things these days. Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
1 parent cb9e291 commit a52e4a2

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

picamera2/picamera2.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import picamera2.utils as utils
2929
from picamera2.allocators import DmaAllocator
3030
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
31-
from picamera2.outputs import FfmpegOutput, FileOutput
31+
from picamera2.outputs import FileOutput, PyavOutput
3232
from picamera2.previews import DrmPreview, NullPreview, QtGlPreview, QtPreview
3333

3434
from .configuration import CameraConfiguration
@@ -2596,26 +2596,36 @@ def start_and_record_video(self, output, encoder=None, config=None, quality=Qual
25962596
example by calling stop_recording).
25972597
25982598
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.
26012600
"""
26022601
if self.started:
26032602
self.stop()
26042603
if not self.camera_config and config is None:
26052604
config = "video"
26062605
if config is not None:
26072606
self.configure(config)
2607+
26082608
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:
26122614
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+
26172625
if encoder is None:
26182626
encoder = H264Encoder()
2627+
encoder.audio = audio
2628+
26192629
self.start_encoder(encoder=encoder, output=output, quality=quality)
26202630
self.start(show_preview=show_preview)
26212631
if duration:

0 commit comments

Comments
 (0)