Is there a preview image in iphone RAW(DNG) file?

Started by namer900, December 24, 2016, 01:21:39 AM

Previous topic - Next topic

namer900

Hello,

I used my iphone to shoot some photos in RAW mode with an App called "procamera". The photos is in DNG format. As I understand it, there supposed to be a low resolution preview embedded in the DNGs. However, I can't use ExifTool to extract it.

Here is an sample file:
https://1drv.ms/u/s!ApWbHSC9NoYSgl4Iigk0YDPJgl8Y

I put the DNGs in D:/test , and then use
exiftool -b -PreviewImage -w jpg -ext dng d:/test
and got nothing.

However, I tried to use another tool
http://www.fsoft.it/ERawP/
I got a small 852*640 resoluton, 212KB size file.

So What Am I Missing Here? Thank you!

Hayo Baan

I just had a look at your file and while it does contain a 852x640 image (apart from the full image data), this is not a "preview" image, at least not in the sense as exiftool sees it. So you won't be able to extract it with e.g. exiftool -b -preview:all -w _prv.jpg -ext dng d:/test.

But since the image data is there, there is probably a way to extract (only) this image. @Phil, (how) can this be done?

Note: when you edit and save the image in e.g. Adobe Camera Raw, it will add previews that are recognisable by exiftool (plus, the preview will be full-sized too – assuming you have the ACR dng options set to generate full sized previews).
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Thanks for the sample.  This JPEG preview is stored in an unusual place for a DNG, and ExifTool doesn't extract it.  I will look into this, but unless I post back here you may assume that the next version of ExifTool (10.38) will extract this preview.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

namer900

Hayo, Phil, Thanks for the answers!

Here is my situation:
I want to shoot raw with my iphone. And since the quality of the embedded image is too low, I have to shoot raw+jpg. However, keeping 2 files for one image is a nightmare to me. So my goal is to batch replacing(using ExifTool) the embedded preview images with the higher quality jpgs, and keeping just 1 file for each photo.
From my  experiment, I also find that by using "Adobe DNG Converter", I can batch convert my iphone DNGs to new DNGs that contain recognizable previews by exiftool. (And then, I can do the exiftool "-previewImage<=d:/test/zz.jpg" d:/test/zz.DNG)

If next version of ExifTool can handle the iphone DNGs directly, maybe I can skip the above conversion step?

I am not sure if it's necessary for you, but I just put more samples here, in case it's helpful for your development of the next version.
They are iPhone app "procamera" shooting(raw+jpg) in landscape/portrait mode. And another app "procam" shooting(raw+jpg) in landscape/portrait mode.
https://1drv.ms/u/s!ApWbHSC9NoYSgl8AyWBjuCBo5wT0

Merry christmas.

Hayo Baan

Quote from: namer900 on December 24, 2016, 04:23:58 PM
If next version of ExifTool can handle the iphone DNGs directly, maybe I can skip the above conversion step?

If it also supports writing the preview, I think you might!

@Phil, I did some experimenting on my own files and found my DNGs actually contain 4 previews. JpgFromRaw, 2 times PreviewImage, and ThumbnailTIFF. So far I have not found a way to specify which of the two preview images to extract (one is in the makernotes). Is there a way to do this? I don't mind if I have to write the code for this myself, but I haven't yet found out how you actually extract the images ;)
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Hi Hayo,

I'll try to make the DNG preview writable.

If there are 2 previews in the same group (presumably the Composite group), the commands to extract them are:

1. exiftool -previewimage -b in.dng > out1.jpg

2. exiftool -copy1:previewimage -b in.dng > out2.jpg

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hayo Baan

Hi Phil,

Excellent, I reckon this copyx: trick also work on other duplicate tags in the same group? Am I correct to further assume that when using the perl library I should use the (x) suffix (like any other duplicate)?

Also, I did some more digging/testing and found the following interesting things:
My (edited) DNGs actually contain multiple Reduced-resolution image entries, all with different sizes:
[EXIF:IFD0]     Subfile Type                    : Reduced-resolution image
[EXIF:IFD0]     Image Width                     : 256
[EXIF:IFD0]     Image Height                    : 171
[EXIF:IFD0]     Compression                     : Uncompressed
[EXIF:IFD0]     Strip Offsets                   : 256764
[EXIF:SubIFD]   Subfile Type                    : Full-resolution Image
[EXIF:SubIFD]   Image Width                     : 3900
[EXIF:SubIFD]   Image Height                    : 2616
[EXIF:SubIFD]   Compression                     : JPEG
[EXIF:SubIFD1]  Subfile Type                    : Reduced-resolution image
[EXIF:SubIFD1]  Image Width                     : 1024
[EXIF:SubIFD1]  Image Height                    : 685
[EXIF:SubIFD1]  Compression                     : JPEG
[EXIF:SubIFD1]  Preview Image Start             : 388092
[EXIF:SubIFD1]  Preview Image Length            : 26059
[EXIF:SubIFD2]  Subfile Type                    : Reduced-resolution image
[EXIF:SubIFD2]  Image Width                     : 3872
[EXIF:SubIFD2]  Image Height                    : 2592
[EXIF:SubIFD2]  Compression                     : JPEG
[EXIF:SubIFD3]  Subfile Type                    : Reduced-resolution image
[EXIF:SubIFD3]  Image Width                     : 2048
[EXIF:SubIFD3]  Image Height                    : 1371
[EXIF:SubIFD3]  Compression                     : Lossy JPEG
[EXIF:SubIFD4]  Subfile Type                    : Reduced-resolution image
[EXIF:SubIFD4]  Image Width                     : 256
[EXIF:SubIFD4]  Image Height                    : 171
[EXIF:SubIFD4]  Compression                     : Lossy JPEG
[MakerNotes:PreviewIFD] Compression             : JPEG (old-style)
[MakerNotes:PreviewIFD] Preview Image Start     : 21472
[MakerNotes:PreviewIFD] Preview Image Length    : 118558

It would be nice if we could extract any of these. Some notes:

  • EXIF:SubIFD2 actually is the JPGFromRaw
  • It looks like EXIF:SubIFD1 is the PreviewImage though for this one the sizes do not match, the resulting JPG is 570x375 not 1024x685 as shown?
  • From the size, either EXIF:IFD0 or EXIF:SubIFD4 could be the ThumbnailTIFF
  • EXIF:SubIFD looks like it is the raw data, but why is the compression for it listed as JPG?
  • The preview in the makernotes is the copy1:PreviewImage (the filesize matches)

Furthermore, I noticed that while the sizes of most of the resulting files when extracting the previews are exactly as mentioned, the "normal" ImagePreview isn't:
[Composite]     Jpg From Raw                    : (Binary data 500886 bytes, use -b option to extract)
[Composite]     Preview Image                   : (Binary data 118558 bytes, use -b option to extract)
[Composite]     Preview Image                   : (Binary data 26059 bytes, use -b option to extract)
[Composite]     Thumbnail TIFF                  : (Binary data 131544 bytes, use -b option to extract)

JpgFromRaw, copy1:PreviewImage, and ThumbnailTIFF are respectively 500886, 118558, and 131544 bytes in size. PreviewImage itself, however, is not 26059, but 144617 bytes...
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: Hayo Baan on December 26, 2016, 05:54:42 AM
I reckon this copyx: trick also work on other duplicate tags in the same group?

Yes.

QuoteAm I correct to further assume that when using the perl library I should use the (x) suffix (like any other duplicate)?

There are other ways to do this via the library -- you can use GetInfo to get all duplicates and sort through them yourself.

QuoteAlso, I did some more digging/testing and found the following interesting things:
My (edited) DNGs actually contain multiple Reduced-resolution image entries, all with different sizes:

Could you email me this sample so I can take a look?  (philharvey66 at gmail.com)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hayo Baan

Sample files sent. Hope they enable you to add easy image extracting functionality to exiftool :)
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: Hayo Baan on December 27, 2016, 03:02:20 AM
Sample files sent. Hope they enable you to add easy image extracting functionality to exiftool :)

Thanks.  I don't think it will be easy though... I'm thinking that the algorithm could handle this better and may need revising.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Hi Hayo,

As far as I can tell, ExifTool is extracting all previews properly from the DNG samples you sent.  Your confusion about the preview image size is that you extracted both previews into a single file.

So I think only problem is that the preview isn't extracted from the iPhone DNG.  I will see about fixing this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hayo Baan

Quote from: Phil Harvey on December 28, 2016, 09:57:18 PM
As far as I can tell, ExifTool is extracting all previews properly from the DNG samples you sent.  Your confusion about the preview image size is that you extracted both previews into a single file.

Ah, you are absolutely right! I have -a enabled by default so it was indeed adding both to the same file. doh ::)

Quote from: Phil Harvey on December 28, 2016, 09:57:18 PM
So I think only problem is that the preview isn't extracted from the iPhone DNG.  I will see about fixing this.

Yes! Hopefully this also enables a way to extract any embedded image file :)
(and perhaps, removing as well ;))
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Well, I've worked about 10 hours on this so far.  I have made some substantial changes to ExifTool that still need testing.  One big change is that the the thumbnail/preview/jpgfromraw images have been moved from the Composite group to the same groups as the tags from which they are derived (ie. EXIF:IFD1 for the ThumbnailImage of a JPEG). This may lead to a bit of confusion since they are in the Composite table of the documentation, but will no longer be in that group.  However, the benefit is that now these images may be addressed by specific location when reading and writing.  It was the writing that was the trickiest, and I still need to test this thoroughly.  If all goes well then ExifTool 10.38 should contain this update.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hayo Baan

Wow, that was a big change! Sounds awesome though 8) Do you need some help testing?

Have you also been able to  have a look at completely removing a complete exif:ifd?
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

I'll let you know about testing.  Maybe I'll post a pre-release when it is closer to release.

I don't want to add the ability to remove an entire IFD right now -- I have to think about this more because it would be very easy to delete something important this way.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).