diff --git a/picamera2/encoders/libav_mjpeg_encoder.py b/picamera2/encoders/libav_mjpeg_encoder.py index c6e21c59..a80e5b54 100644 --- a/picamera2/encoders/libav_mjpeg_encoder.py +++ b/picamera2/encoders/libav_mjpeg_encoder.py @@ -47,7 +47,7 @@ def _start(self): self._stream.width = self.width self._stream.height = self.height - self._stream.pix_fmt = "yuv420p" + self._stream.pix_fmt = "yuvj420p" for out in self._output: out._add_stream(self._stream, self._codec, rate=self.framerate) @@ -64,7 +64,7 @@ def _start(self): self._stream.codec_context.qmin = self.qp self._stream.codec_context.qmax = self.qp - self._stream.codec_context.color_range = 2 # JPEG (full range) + try: # "qscale" is now correct, but some older versions used "QSCALE" self._stream.codec_context.flags |= av.codec.context.Flags.qscale # noqa @@ -73,7 +73,7 @@ def _start(self): self._stream.codec_context.time_base = Fraction(1, 1000000) - FORMAT_TABLE = {"YUV420": "yuv420p", + FORMAT_TABLE = {"YUV420": "yuvj420p", "BGR888": "rgb24", "RGB888": "bgr24", "XBGR8888": "rgba", diff --git a/picamera2/outputs/pyavoutput.py b/picamera2/outputs/pyavoutput.py index 54639632..20436630 100644 --- a/picamera2/outputs/pyavoutput.py +++ b/picamera2/outputs/pyavoutput.py @@ -30,12 +30,15 @@ def __init__(self, output_name, format=None, pts=None): def _add_stream(self, encoder_stream, codec_name, **kwargs): # The output container that does the muxing needs to know about the streams for which packets # will be sent to it. It literally needs to copy them for the output container. + print(encoder_stream) + print() stream = self._container.add_stream(codec_name, **kwargs) - - if codec_name == "mjpeg": - # Well, this is nasty. MJPEG seems to need this. - stream.codec_context.color_range = 2 # JPEG (full range) - + print(stream) + stream.codec_context.width = encoder_stream.codec_context.width + stream.codec_context.height = encoder_stream.codec_context.height + stream.codec_context.pix_fmt = encoder_stream.codec_context.pix_fmt + print(stream) + self._streams[encoder_stream] = stream def start(self):