Skip to content

use yuvj420 (pyav jpeg full range) #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions picamera2/encoders/libav_mjpeg_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions picamera2/outputs/pyavoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down