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

RAW+JPEG files not converted with --convert-to-jpeg #469

Closed
neilpa opened this issue Jun 16, 2021 · 12 comments
Closed

RAW+JPEG files not converted with --convert-to-jpeg #469

neilpa opened this issue Jun 16, 2021 · 12 comments
Labels
documentation Improvements or additions to documentation

Comments

@neilpa
Copy link

neilpa commented Jun 16, 2021

Noticed that some (all?) of my photos that are RAW+JPEG aren't converted when exported with --convert-to-jpeg. I've seen this for both Sony .arw and Nikon .nef files I have. Here's the full command that I'm running

osxphotos export \
  --update \
  --db $DB \
  --directory '{created.year}/{created.mm}.{created.mon|lower}/{created.dd}' \
  --filename '{function:templates.py::filename_prefix}.{original_name}.{uuid}' \
  --convert-to-jpeg \
  --jpeg-ext jpeg \
  --skip-original-if-edited \
  --edited-suffix '' \
  --exiftool \
  --sidecar xmp \
  --sidecar json \
  --strip \
  --verbose \
  --report $LOGS/$TS.report.csv \
  $EXPORT

If you need it I can also put together a test db with a few of the problematic files.

@RhetTbull
Copy link
Owner

A small test db would be great! You can email it or a link to me at Rturnbull+git@gmail.com I'm traveling and won't be able to take a look until this weekend.

@RhetTbull
Copy link
Owner

Just looked at the code in _photoinfo_export.py and I think I see the issue. RAW+JPEG have a UTI of 'public.jpeg' in Photos even if the RAW is selected as the original so the conversion never gets triggered. Will need to think about the best way to bands this. Not sure everyone will want the raw converted if there's already a jpeg. Also need to avoid name collisions when the jpeg is also exported.

uti = self.uti if edited else self.uti_original
    if convert_to_jpeg and self.isphoto and uti != "public.jpeg":
        # not a jpeg but will convert to jpeg upon export so fix file extension
        fname_new = pathlib.Path(fname)
        ext = "." + jpeg_ext if jpeg_ext else ".jpeg"
        fname = str(fname_new.parent / f"{fname_new.stem}{ext}")
    else:
        # nothing to convert
        convert_to_jpeg = False

@RhetTbull
Copy link
Owner

@RhetTbull
Copy link
Owner

PS -- you get the osxphotos Power User badge! Love to see some of the newer features like template filters and functions "in the wild"!

@neilpa
Copy link
Author

neilpa commented Jun 16, 2021

PS -- you get the osxphotos Power User badge! Love to see some of the newer features like template filters and functions "in the wild"!

Yea, I was experimenting with it yesterday and it worked out great for customizing export names just how I want them.

@neilpa
Copy link
Author

neilpa commented Jun 16, 2021

RAW+JPEG have a UTI of 'public.jpeg' in Photos even if the RAW is selected as the original so the conversion never gets triggered. Will need to think about the best way to bands this. Not sure everyone will want the raw converted if there's already a jpeg.

Ahh, I didn't realize that they both got exported. In that case, seems like if --convert-to-jpeg is specified it should just skip the RAW entirely since the associated JPEG is already getting exported.

@RhetTbull
Copy link
Owner

RhetTbull commented Jun 16, 2021

Ahh, I didn't realize that they both got exported. In that case, seems like if --convert-to-jpeg is specified it should just skip the RAW entirely since the associated JPEG is already getting exported.

At the very least, I need to update the documentation to make it clear what happens in the case of RAW+JPEG.

You could use --skip-raw to skip the RAW component of the RAW+JPEG pair and this may eliminate the need to have separate logic in the export code to deal with RAW+JPEG and conversion. The way RAW images are handled in the Photos database makes it tricky to deal with these in a uniform way.

@RhetTbull RhetTbull added the documentation Improvements or additions to documentation label Jun 16, 2021
@neilpa
Copy link
Author

neilpa commented Jun 16, 2021

You could use --skip-raw to skip the RAW component of the RAW+JPEG pair and this may eliminate the need to have separate logic in the export code to deal with RAW+JPEG and conversion.

The majority of my photos are plain RAW files. Wouldn't that also skip those rather than convert them to JPEG?

@neilpa
Copy link
Author

neilpa commented Jun 16, 2021

You could use --skip-raw to skip the RAW component of the RAW+JPEG pair and this may eliminate the need to have separate logic in the export code to deal with RAW+JPEG and conversion.

The majority of my photos are plain RAW files. Wouldn't that also skip those rather than convert them to JPEG?

Just re-read the docs. That's definitely what I want. Thanks!

  --skip-raw                      Do not export associated raw images of a
                                  RAW+JPEG pair.  Note: this does not skip raw
                                  photos if the raw photo does not have an
                                  associated jpeg image (e.g. the raw file was
                                  imported to Photos without a jpeg preview).

@RhetTbull
Copy link
Owner

The majority of my photos are plain RAW files. Wouldn't that also skip those rather than convert them to JPEG?

No. It only skips the RAW component of the RAW+JPEG pair. (And thus, perhaps the --skip-raw flag is not the best name, though the help text for the flag does try to clarify. The other --skip-X flags all behave similarly,e.g. --skip-live skips the associated live movie for a live image but still exports the actual image, --skip-edited skips the edited version but still exports the original,etc.)

Here's the actual code: it looks at photo.has_raw which is True if the photo has an associated RAW image but False if the photo is itself a RAW image without a JPEG pair as yours are. Setting --skip-raw toggles raw_photo to False in the snippet below.

# copy associated RAW image if requested
if raw_photo and self.has_raw:
raw_path = pathlib.Path(self.path_raw)
raw_ext = raw_path.suffix
raw_name = dest.parent / f"{dest.stem}{raw_ext}"
if raw_path is not None:
results = self._export_photo(
raw_path,
raw_name,
update,
export_db,
overwrite,
export_as_hardlink,
exiftool,
touch_file,
convert_to_jpeg,
fileutil=fileutil,
jpeg_quality=jpeg_quality,
ignore_signature=ignore_signature,
)
all_results += results

@neilpa
Copy link
Author

neilpa commented Jun 16, 2021

--skip-live skips the associated live movie for a live image but still exports the actual image

Another flag I probably want since I've got a few of those imported.

RhetTbull added a commit that referenced this issue Jun 19, 2021
@RhetTbull
Copy link
Owner

I updated the help text in v0.42.39 to try to make it more clear what --convert-to-jpeg actually does with RAW+JPEG pairs.

@neilpa neilpa closed this as completed Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants