Skip to content
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

Create a small application #107

Open
FredWahl opened this issue Oct 29, 2022 · 10 comments
Open

Create a small application #107

FredWahl opened this issue Oct 29, 2022 · 10 comments

Comments

@FredWahl
Copy link

Using your own code, you could make a very useful application. It shoud be given a path and it shoul iterate over all files in tis directory and the sub direcories. It should do the safest thing i.e. make the jpg smaller such that is pixel by pixel identical. When a jpg is found, let mozjpeg create something like jpg.tmp. If this file is smaller, the original file can be overwritten by the contents of jpg.tmp. Either way, jpg.tmp shpuld be deleted afterwards. This is better than deleting the original file and then renaming jpg.tmp since it will cause fragmentation. Most jpg files from your smartcam can be reduced by 6% or so and most people have folders with lots of jpeg files.

Best regards,
Fredrik

@georg-jung
Copy link
Owner

georg-jung commented Jan 5, 2023

You could take a look at my MozJPEG UI in the Microsoft Store. It's quite new and not 100% production ready. It also does not exactly what you were asking for but it comes reasonable close I guess.

Note that jpegs that are recompressed using MozJpeg can be visually indistinguishable from the originals (given a high enough quality setting) but are generally not pixel by pixel identical.

Happy to hear your feedback if you give it a try.

@FredWahl
Copy link
Author

FredWahl commented Jan 5, 2023 via email

@FredWahl
Copy link
Author

FredWahl commented Jan 5, 2023 via email

@georg-jung
Copy link
Owner

georg-jung commented Jan 5, 2023

Which options for jpegtran do you use?

As jpeg is a lossy compression mechanism, recompression typically leads to some loss in quality and to not pixel-by-pixel identical images. This also explains why your images grow again if you process them twice. Compression artefacts are often hard to compress themselves. Thus, if you compress an image over and over again it might sometimes grow in size. If you think there is any metadata that is responsible for a larger or smaller file, you could check with exiftool.

Edit:

Ah, I see, your talking about this part of MozJPEGs readme:

It can be applied to any JPEG file (with jpegtran) to losslessly reduce file size.

This is actually not what my UI (currently) does and also not what MozJpegSharp's MozJpeg.Recompress does. I will consider to add such an option though.

@FredWahl
Copy link
Author

FredWahl commented Jan 5, 2023 via email

@FredWahl
Copy link
Author

FredWahl commented Jan 5, 2023 via email

@georg-jung
Copy link
Owner

Thanks for your detailed explanations and ideas!

I see how many of your points might be useful to users. However, my top priority is to keep the app as simple as possible and thus to offer the least amount of options possible while still beeing useful. I'll probably focus on features that seem most important to an average user to me or I like in some special way. In general, the goal is to just solve the compression problem and keep it really simple.

Summarising the ideas (please correct me if I got something wrong, order by occurence):

  1. Progressbar
  2. ETA
  3. Lossless recompress
  4. Renaming
  5. Avoid useless/harmfull re-recompression
  6. Support restarts

1 & 2
I'm right there with you, they should exist. First and foremost the progress bar.

3
I really understand your feeling towards keeping images as pixel perfect copies, as I'm a hobby photographer too - not an astronomer though. My workflow is fully RAW-based and I just export jpgs. Thus, from my perspective I always have a pixel perfect copy but my priority when creating jpgs is to have the best quality/size ratio possible. To achieve this I'd export from Lightroom as tiff/... and then compress using MozJPEG. The best quality/size ratio will just be achieved by actually compressing with MozJPEG. I assume, most people are more interested in real jpg re-encoding because that can easily achieve improvement rates of about 50%, while lossless recompression is about 5% for pictures I tested with. Those who really care about pixel-perfectness are typically using raw workflows in the first place, I guess. I still like the idea though and might add it to the advanced options in a future version.

4
I won't implement any renaming over what is required for keeping the originals. I think there are other options available which specialize in renaming and probably do this better then I ever could with reasonable amounts of effort put in. I agree it'd be nice to have an all in one solution, but in the end this is still a hobby project with limited available resources and I think adding a basic and not thought-through-to-the-end renaming solution would do more harm to this software than provide use.

5
This is already implemented. In the settings you can select a "Skip if size reduction is below" percentage. I think this is the easiest and most straight forward way without adding any proprietary metadata or anything like that. It feels right to me not to add anything proprietary. Also it judges from the outcome point of view which I feel is most useful. Why care if this software already touched the image? Just process it if processing has a reasonable positive effect. Currently the steps are 1, 5, 10, 15, 20, 30, 40, 50. If I add the lossless recompress it might be worth considering to add more steps in between. However, if it's lossless either way, why not just use the 1% option?

6
I see how this might be useful for large image archives. I think however that it is non-trivial to implement correctly. If I'd have a huge image archive, wouldn't I then have the option to keep my PC running for some days or otherwise, as a workaround, process my images in batches (e.g. put 50k images first, then reboot, then continue, ...). I still see how this might be beneficial. It could be a feature that wouldn't require any visible options before it is actually needed, e.g. ask for continuing when restarted much like Excel asks you something like "Do you want to keep these restored files from your last session?". I might consider adding this in the future.

Please don't be frustrated, I really appreciate all your ideas and well thought out proposals! Reality is just that I have limited time to invest in this early hobby project that currently probably has less than 5 users. Going forward I'll come back to this thread and consider the above points when I think about what to implement next. I never planned to make anything bigger than a very basic and simple MozJPEG UI though.

@FredWahl
Copy link
Author

FredWahl commented Jan 6, 2023 via email

@georg-jung
Copy link
Owner

If you search for *.jpg files you won’t find the other ones.

I don't search for any file extension currently, I just take what the user drag-n-drops. It is supported to drop any non-jpeg image types GDI+ supports, e.g. tiff, bmp, png, ...; if any non image type is dropped, the conversion of this file is marked as error and I continue with the next one.

Do you use CreateProcess?

I don't. MozJPEG UI uses my MozJpegSharp library which is a managed dotnet wrapper for the unmanaged mozjpeg library. Thus, I don't create any processes but rather directly consume the library (which is what the mozjpeg authors suggest one should do).

Actually, even pixel perfect files can be reduced by a large number if you don’t copy comments.

I see. I currently copy any metadata I can because I want to keep exif data in general and "what to copy" is probably a question that is non-trivial to answer. I assume other software exists that helps with metadata removal. I might add an option "copy metadata", all or nothing. This is however nothing I need for myself right now, as the typical photo that drops out of a RAW->Lightroom->JPEG workflow does not have huge metadata from my experience.

Please note that the first version, that is currently in the Microsoft Store doesn't really compress using MozJPEG but rather just using libjpeg-turbo, due to a bug (probably in MozJPEG's latest commit itself). So it'd be better to wait for the next one (based on MozJPEGs second newest commit) before any serious use (it is not possible to find using Store search, just if one knows the link, so no concerns there).

@FredWahl
Copy link
Author

FredWahl commented Jan 6, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants