[bug] low quality image is not properly aligned

On my OnePlus 5, when I set the image to low quality to save space and bandwidth, either the aspect ratio mismatch or the cropping causes the HUD target thing to be misaligned.

The images below were taken with the phone in the exact same place:

Needs scaling and testing on screens with extreme aspect ratios?

edit: also, some thoughts around this point/feature:

  • The low/high quality switch is a bit extreme on recent phones. For me the options are from 3456x4608 (15 megapixels) or 1280x720 0.9 megapixels.
  • Using webp saves about 1/3 in OpenCamera on Android.
  • Thinking of using stuff learned from modern video codecs, saving the whole sequence using h.264 might yield reasonable results.

A thought about using h264. Compared to a single jpg, a h264 compressed stream generally yields artifact/noise/glug when decoded back into images again.This does of course depend on the bitrate.

The cool thing about h.264 is that a frame can be built from up to five different reference frames, so a number of frames could share the same compressed block data. I don’t know if the encoders have much support for that though. A simpler hack could be to just combine 4 images into one huge one and compress the whole thing in one go, I’d imagine that would reduce the final size a fair bit without losing too much quality.

I have not really done any work on this, but something like ffmpeg could create a high quality mkv (defaults to h264) thus;

find . -size +10k -name “*jpg”|sort| xargs -I ‘{}’ cat ‘{}’|ffmpeg -r 10 -vcodec mjpeg -f image2pipe -i - -crf 5 -r 10 -s 3456x4608 -y output.mkv

The crf paramater of 15-20 is more common for movies so have a play with that to balance up compression vs quality. (lower the number, higher the quality)

To revert the movie stream back to jpg’s

ffmpeg -i output.mkv -loglevel quiet -qscale:v 1 -qmin 1 -nostdin frame_%06d.jpg

1 Like

Cool, thanks. No promises but I might do some experiments and share the different methods, source data and results here in case it helps the devs. Performance engineering is my day job and is fun science, even moreso when doing it for something I really care about!

The mkv-jpg conversion is almost a copy of the code used in mapillary_tools for the (now deprecated) local image file creation of BlackVue, GoPro and other movie based capture. (the rate argument has been removed. eg convert a 30FPS movie to 5FPS images) Nowadays they prefer the movies uploaded to process at the server end, but I would suspect the code is similar.

qscale:v 2 equates to about a 87% jpeg quality and qscale:v 1 -qmin 1 between 95 and 100. (The default best quality is 2 unless overridden by the qmin argument)