So I think x264 does have support for greyscale (i.e. single channel) images, though Picamera2 will always give you YUV420, even if there's no colour information. You could certainly have a go at hacking the code to try and pass in only the greyscale part of the image - it might "just work", but I wouldn't like to promise it!
Having said that, YUV420 is only 50% larger than a single channel image so it's not like you're doing 3 times the work. You could make some modifications in the camera tuning file to force a greyscale output (where "grey" could be any colour channel or combination that you like), and all the UV values will be 128. Clearly those UV values won't contribute much to your bitstream, and when you decode it on the other end, you know that "Y" is already the thing that you want (though you might have to be careful about "limited range" encodings).
You might still be spending a small amount of time encoding those pointless UV values, but I think it is marginal. x264 might have some options to avoid things like motion estimation on the chroma channels, but PyAV may well not expose it. On the other hand, it might be that chroma ME gets disabled automatically for the fast encode presets - that's asking for more details about libx264 than I know! Perhaps someone else can fill me in here...
If you wanted to try forcing greyscale output (even if still in YUV420 format), you should edit the colour matrices so that they will give you the same output on each channel. You can find them in the tuning file under "rpi.ccm" in the JSON file.
Having said that, YUV420 is only 50% larger than a single channel image so it's not like you're doing 3 times the work. You could make some modifications in the camera tuning file to force a greyscale output (where "grey" could be any colour channel or combination that you like), and all the UV values will be 128. Clearly those UV values won't contribute much to your bitstream, and when you decode it on the other end, you know that "Y" is already the thing that you want (though you might have to be careful about "limited range" encodings).
You might still be spending a small amount of time encoding those pointless UV values, but I think it is marginal. x264 might have some options to avoid things like motion estimation on the chroma channels, but PyAV may well not expose it. On the other hand, it might be that chroma ME gets disabled automatically for the fast encode presets - that's asking for more details about libx264 than I know! Perhaps someone else can fill me in here...
If you wanted to try forcing greyscale output (even if still in YUV420 format), you should edit the colour matrices so that they will give you the same output on each channel. You can find them in the tuning file under "rpi.ccm" in the JSON file.
Statistics: Posted by therealdavidp — Thu Mar 06, 2025 3:58 pm