JPEG files are saved padded with 21Mb of zeroes when using Camera2 API
Camera app for Android.
Brought to you by:
mark-h
I installed OpenCamera 1.43.3 on my Samsung Galaxy A5 2017, and when I enable Camera2 I get a really nice manual focus mode, but the size of JPEG files saved by OpenCamera spikes from 2.7Mb to 31Mb.
I analyzed the large JPEG files with exifprobe and an hex viewer, and found out that they are normal JPEG files, with 29Mb of zeroes padded at the end.
I'm attaching one such image.
I now disabled Camera2 by default, and I'll turn it on only when I'll want to use manual focus, then I'll need to write a tool to truncate the files at the end of the JPEG content.
Anonymous
Same phone same problem here same fix. There is indeed a long string of zeroes but it's not strictly at end of file. The last 8 bytes are an end marker and they are not all zeroes.
The last bytes look like ff 00 xx xx 00 00 e6 01 . As a result, a program that removes trailing nuls like on https://www.unix.com/302975313-post4.html?s=a4ce331ef3314912ebd1b4cec4c1b39a does nothing.
One solution is to use
jpegtranto process files. That program processes a JPEG stream losslessly. See https://en.wikipedia.org/wiki/Libjpeg for details. I'm using Linux, so a command line can process files in batch (and keep backups), what about you?My recommendation for the Anonymous above is to use a good image editor which can batch process files (Photo Editor): https://play.google.com/store/apps/details?id=com.iudesk.android.photo.editor
Then, just share your photos with the included Batch app, choose the task Format and set your favorite JPEG options, then it will process all images. And these 30mb will be cleared.
Same phone, same problem. I'd really like someone to fix this in the app, but until then here's a cookbook solution:
Install termux
Open termux, copy the code below and longpress in window to copy it:
termux-setup-storage
(press enter, choose yes to storage permission)
Next copy this code and press enter:
pkg install libjpeg-turbo-progs
(Press y and enter to allow installation)
Now copy this code and press enter (make sure it gets copied without any linebreaks)
du -s -h ~/storage/dcim/OpenCamera/; for i in ~/storage/dcim/OpenCamera/*.jpg; do jpegtran -copy all -outfile $i $i; echo -n "."; done; echo; du -s -h ~/storage/dcim/OpenCamera/
That should fix all the files in your camera folder.
Repeat the last step whenever you need. You can skip the copy-paste by using the up arrow over the keyboard in termux to access past commands.
Notice that all the files in the folder will be processed whether they need or not, maybe move the fixed files to another folder if it gets too slow.
The program also shows the space used in the folder before and after running.
You may have to change the folder names in the script if your phone puts the pics elsewhere.
Good luck :-)
Thanks for the info!
Also see https://sourceforge.net/p/opencamera/discussion/general/thread/77492f4d/ .