使用 exiftool 从 CR2 图像中提取缩略图

使用 exiftool 从 CR2 图像中提取缩略图

我正在尝试在 Windows 中使用 从 CR2 图像中提取 JPEG 缩略图exiftool

我成功地做到了这一点程序 QuickJPGFromCR2。从描述来看,它似乎从 EXIF 数据中提取 JPEG 预览。生成的文件与原始图像的宽度和高度相同,对于我处理的文件,大小在 1~2 MB 之间。

首先,的输出exiftool .\Kendall_FACS_0002_0100A.cr2如下:

ExifTool Version Number         : 10.45
File Name                       : Kendall_FACS_0002_0100A.cr2
Directory                       : .
File Size                       : 25 MB
File Modification Date/Time     : 2016:10:20 14:47:47-05:00
File Access Date/Time           : 2016:11:21 18:26:10-06:00
File Creation Date/Time         : 2017:01:23 14:14:05-06:00
File Permissions                : rw-rw-rw-
File Type                       : CR2
File Type Extension             : cr2
MIME Type                       : image/x-canon-cr2
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 5184
Image Height                    : 3456
Bits Per Sample                 : 8 8 8
Compression                     : JPEG (old-style)
Make                            : Canon
Camera Model Name               : Canon EOS REBEL T3i
Preview Image Start             : 68120
Orientation                     : Horizontal (normal)
Preview Image Length            : 1708300
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Modify Date                     : 2016:10:20 14:46:19
Artist                          : 
Rating                          : 0
Copyright                       : 
Exposure Time                   : 1/100
F Number                        : 16.0
Exposure Program                : Manual
ISO                             : 100
Sensitivity Type                : Recommended Exposure Index
Recommended Exposure Index      : 100
Exif Version                    : 0230
Date/Time Original              : 2016:10:20 14:46:19
Create Date                     : 2016:10:20 14:46:19
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/99
Aperture Value                  : 16.0
Flash                           : Off, Did not fire
Focal Length                    : 40.0 mm
Macro Mode                      : Normal
Self Timer                      : Off
Quality                         : RAW
Canon Flash Mode                : Off
Continuous Drive                : Single
Focus Mode                      : Manual Focus (3)
Record Mode                     : CR2
Canon Image Size                : n/a
Easy Mode                       : Manual
Digital Zoom                    : None
Contrast                        : Normal
Saturation                      : Normal
Metering Mode                   : Evaluative
Focus Range                     : Not Known
Canon Exposure Mode             : Manual
Lens Type                       : Canon EF 40mm f/2.8 STM
Max Focal Length                : 40 mm
Min Focal Length                : 40 mm
Focal Units                     : 1/mm
Max Aperture                    : 2.8
Min Aperture                    : 23
Flash Activity                  : 0
Flash Bits                      : (none)
Zoom Source Width               : 0
Zoom Target Width               : 0
Manual Flash Output             : n/a
Color Tone                      : Normal
SRAW Quality                    : n/a
Auto ISO                        : 100
Base ISO                        : 100
Measured EV                     : 6.00
Target Aperture                 : 16
Target Exposure Time            : 1/102
Exposure Compensation           : 0
White Balance                   : Daylight
Slow Shutter                    : None
Shot Number In Continuous Burst : 0
Optical Zoom Code               : n/a
Camera Temperature              : 30 C
Flash Guide Number              : 0
Flash Exposure Compensation     : 0
Auto Exposure Bracketing        : Off
AEB Bracket Value               : 0
Control Mode                    : Camera Local Control
Measured EV 2                   : 6.625
Bulb Duration                   : 0
Camera Type                     : EOS High-end
ND Filter                       : n/a
Canon Image Type                : Canon EOS REBEL T3i
Canon Firmware Version          : Firmware Version 1.0.2
Flash Metering Mode             : Off
Camera Orientation              : Horizontal (normal)
Firmware Version                : 1.0.2
File Index                      : 2
Directory Index                 : 100
Contrast Standard               : 0
Sharpness Standard              : 3
Saturation Standard             : 0
Color Tone Standard             : 0
Contrast Portrait               : 0
Sharpness Portrait              : 2
Saturation Portrait             : 0
Color Tone Portrait             : 0
Contrast Landscape              : 0
Sharpness Landscape             : 4
Saturation Landscape            : 0
Color Tone Landscape            : 0
Contrast Neutral                : 0
Sharpness Neutral               : 0
Saturation Neutral              : 0
Color Tone Neutral              : 0
Contrast Faithful               : 0
Sharpness Faithful              : 0
Saturation Faithful             : 0
Color Tone Faithful             : 0
Contrast Monochrome             : 0
Sharpness Monochrome            : 3
Filter Effect Monochrome        : None
Toning Effect Monochrome        : None
Contrast Auto                   : 0
Sharpness Auto                  : 3
Saturation Auto                 : 0
Color Tone Auto                 : 0
Filter Effect Auto              : n/a
Toning Effect Auto              : n/a
Contrast User Def 1             : 0
Sharpness User Def 1            : 3
Saturation User Def 1           : 0
Color Tone User Def 1           : 0
Filter Effect User Def 1        : None
Toning Effect User Def 1        : None
Contrast User Def 2             : 0
Sharpness User Def 2            : 3
Saturation User Def 2           : 0
Color Tone User Def 2           : 0
Filter Effect User Def 2        : None
Toning Effect User Def 2        : None
Contrast User Def 3             : 0
Sharpness User Def 3            : 3
Saturation User Def 3           : 0
Color Tone User Def 3           : 0
Filter Effect User Def 3        : None
Toning Effect User Def 3        : None
User Def 1 Picture Style        : Auto
User Def 2 Picture Style        : Auto
User Def 3 Picture Style        : Auto
Canon Model ID                  : EOS Rebel T3i / 600D / Kiss X5
Thumbnail Image Valid Area      : 0 159 7 112
AF Area Mode                    : Off (Manual Focus)
Num AF Points                   : 9
Valid AF Points                 : 9
Canon Image Width               : 5184
Canon Image Height              : 3456
AF Image Width                  : 5184
AF Image Height                 : 3456
AF Area Widths                  : 139 139 139 196 238 196 139 139 139
AF Area Heights                 : 186 186 186 127 231 127 186 186 186
AF Area X Positions             : -1477 -886 -886 0 0 0 886 886 1477
AF Area Y Positions             : 0 418 -418 787 0 -787 418 -418 0
AF Points In Focus              : (none)
AF Points Selected              : 0,1,2,3,4,5,6,7,8
Original Decision Data Offset   : 0
Bracket Mode                    : Off
Bracket Value                   : 0
Bracket Shot Number             : 0
Raw Jpg Size                    : Large
Long Exposure Noise Reduction 2 : Off
WB Bracket Mode                 : Off
WB Bracket Value AB             : 0
WB Bracket Value GM             : 0
Live View Shooting              : Off
Focus Distance Upper            : 2.16 m
Focus Distance Lower            : 1.46 m
Flash Exposure Lock             : Off
Internal Serial Number          : ZC1954285
Dust Removal Data               : (Binary data 1024 bytes, use -b option to extract)
Crop Left Margin                : 0
Crop Right Margin               : 0
Crop Top Margin                 : 0
Crop Bottom Margin              : 0
Exposure Level Increments       : 1/3 Stop
ISO Expansion                   : Off
Flash Sync Speed Av             : Auto
Long Exposure Noise Reduction   : Off
High ISO Noise Reduction        : Standard
Highlight Tone Priority         : Disable
AF Assist Beam                  : Does not emit
Mirror Lockup                   : Enable
Shutter-AE Lock                 : AF/AE lock
Set Button When Shooting        : Normal (disabled)
LCD Display At Power On         : Display
Add Original Decision Data      : Off
Aspect Ratio                    : 3:2
Cropped Image Width             : 5184
Cropped Image Height            : 3456
Cropped Image Left              : 0
Cropped Image Top               : 0
Tone Curve                      : Standard
Sharpness                       : 3
Sharpness Frequency             : n/a
Sensor Red Level                : 0
Sensor Blue Level               : 0
White Balance Red               : 0
White Balance Blue              : 0
Color Temperature               : 5200
Picture Style                   : Auto
Digital Gain                    : 0
WB Shift AB                     : 0
WB Shift GM                     : 0
Measured RGGB                   : 431 1024 1024 768
VRD Offset                      : 0
Sensor Width                    : 5344
Sensor Height                   : 3516
Sensor Left Border              : 152
Sensor Top Border               : 56
Sensor Right Border             : 5335
Sensor Bottom Border            : 3511
Black Mask Left Border          : 0
Black Mask Top Border           : 0
Black Mask Right Border         : 0
Black Mask Bottom Border        : 0
Color Data Version              : 10 (600D/1200D)
WB RGGB Levels As Shot          : 2123 1024 1024 1556
Color Temp As Shot              : 5200
WB RGGB Levels Auto             : 2028 1024 1024 1606
Color Temp Auto                 : 4908
WB RGGB Levels Measured         : 2028 1024 1024 1606
Color Temp Measured             : 4908
WB RGGB Levels Daylight         : 2123 1024 1024 1556
Color Temp Daylight             : 5200
WB RGGB Levels Shade            : 2439 1024 1024 1321
Color Temp Shade                : 7000
WB RGGB Levels Cloudy           : 2280 1024 1024 1431
Color Temp Cloudy               : 6000
WB RGGB Levels Tungsten         : 1540 1024 1024 2341
Color Temp Tungsten             : 3200
WB RGGB Levels Fluorescent      : 1869 1024 1024 2226
Color Temp Fluorescent          : 3729
WB RGGB Levels Kelvin           : 2123 1024 1024 1556
Color Temp Kelvin               : 5200
WB RGGB Levels Flash            : 2367 1024 1024 1411
Color Temp Flash                : 6303
Average Black Level             : 2048 2048 2048 2048
Raw Measured RGGB               : 99047 229396 224807 170653
Per Channel Black Level         : 2047 2047 2048 2048
Normal White Level              : 11767
Specular White Level            : 12279
Linearity Upper Margin          : 10000
Picture Style User Def          : Auto; Auto; Auto
Picture Style PC                : None; None; None
Custom Picture Style File Name  : 
Vignetting Corr Version         : 0
Peripheral Lighting             : Off
Chromatic Aberration Corr       : Off
Peripheral Lighting Value       : 0
Original Image Width            : 5184
Original Image Height           : 3456
Peripheral Lighting Setting     : Off
Peripheral Illumination Corr    : Off
Auto Lighting Optimizer         : Off
User Comment                    : 
Sub Sec Time                    : 46
Sub Sec Time Original           : 46
Sub Sec Time Digitized          : 46
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 5184
Exif Image Height               : 3456
Interoperability Index          : R98 - DCF basic file (sRGB)
Interoperability Version        : 0100
Focal Plane X Resolution        : 5728.176796
Focal Plane Y Resolution        : 5808.403361
Focal Plane Resolution Unit     : inches
Custom Rendered                 : Normal
Exposure Mode                   : Manual
Scene Capture Type              : Standard
Owner Name                      : CAM1100A1
Serial Number                   : 252076117630
Lens Info                       : 40mm f/?
Lens Model                      : EF40mm f/2.8 STM
Lens Serial Number              : 00002bc0be
Thumbnail Offset                : 55048
Thumbnail Length                : 13072
Photometric Interpretation      : RGB
Samples Per Pixel               : 3
Rows Per Strip                  : 432
Planar Configuration            : Chunky
Strip Offsets                   : 3513124
Strip Byte Counts               : 22248252
Raw Image Segmentation          : 2 1728 1888
SRaw Type                       : 1
Aperture                        : 16.0
Drive Mode                      : Single-frame Shooting
File Number                     : 100-0002
Image Size                      : 5184x3456
Lens                            : 40.0 mm
Lens ID                         : Canon EF 40mm f/2.8 STM
Megapixels                      : 17.9
Preview Image                   : (Binary data 1708300 bytes, use -b option to extract)
Scale Factor To 35 mm Equivalent: 1.6
Shooting Mode                   : Manual
Shutter Speed                   : 1/100
Create Date                     : 2016:10:20 14:46:19.46
Date/Time Original              : 2016:10:20 14:46:19.46
Modify Date                     : 2016:10:20 14:46:19.46
Thumbnail Image                 : (Binary data 13072 bytes, use -b option to extract)
WB RGGB Levels                  : 2123 1024 1024 1556
Blue Balance                    : 1.519531
Circle Of Confusion             : 0.019 mm
Depth Of Field                  : 1.38 m (1.35 - 2.73 m)
Field Of View                   : 31.9 deg
Focal Length                    : 40.0 mm (35 mm equivalent: 62.9 mm)
Hyperfocal Distance             : 5.23 m
Lens                            : 40.0 mm (35 mm equivalent: 62.9 mm)
Light Value                     : 14.6
Red Balance                     : 2.073242

因此,查看二进制数据字段(建议使用该-b选项提取的字段),我们得到:

Dust Removal Data               : (Binary data 1024 bytes, use -b option to extract)
Preview Image                   : (Binary data 1708300 bytes, use -b option to extract)
Thumbnail Image                 : (Binary data 13072 bytes, use -b option to extract)

标签Preview Image看起来就是我们要找的,而且Thumbnail Image也很有趣(虽然很小)。

运行以下命令:

exiftool -b .\Kendall_FACS_0002_0100A.cr2 > out.jpg
exiftool -b -PreviewImage .\Kendall_FACS_0002_0100A.cr2 > out.jpg
exiftool -b -ThumbnailImage .\Kendall_FACS_0002_0100A.cr2 > out.jpg

前两个命令生成的文件大小为 3.28 MB,而最后一个命令生成的文件大小仅为 25.6KB。所有文件均无法在任何程序中打开。Windows Photo Viewer 提示无法打开该文件,因为the file appears to be damaged, corrputed, or is too large

使用 ImageMagick 的identify命令将为标签提供以下输出Preview Image

exiftool -b -PreviewImage .\Kendall_FACS_0002_0100A.cr2 | identify -
identify.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.

exiftool -b -PreviewImage .\Kendall_FACS_0002_0100A.cr2 | identify jpg:-
identify.exe: Not a JPEG file: starts with 0x3f 0x3f `-' @ error/jpeg.c/JPEGErrorHandler/322.

我注意到互联网上的其他地方也有人使用该-JpegFromRaw选项,但我的 EXIF 数据没有这样的标签。

那么,我到底做错了什么?

答案1

在第一个命令中,您将提取所有原始元数据并将其保存到 out.jpg 中。这会创建一个不是图像的垃圾文件。第二个和第三个命令应该有效,它们对我拥有的 .cr2 样本有效。PreviewImage 是一个嵌入的 jpg,如果您的相机设置为保存 Jpgs+Raw,它应该与创建的 jpg 相同。ThumbnailImage 是一个非常小的 jpg(在我的样本中为 160x120),一些程序可以将其用作缩略图以加快图像浏览速度。

我相信 JpegFromRaw 选项用于从一些较旧的相机中提取预览,它可能不会对您的相机产生任何作用。

您正在使用哪个版本的 exiftool(类型exiftool -ver)?

exiftool -b -PreviewImage .\Kendall_FACS_0002_0100A.cr2 > out.jpg和都exiftool -b -ThumbnailImage .\Kendall_FACS_0002_0100A.cr2 > out.jpg应该可以工作。

编辑: 经过我们进行的一些测试,似乎 PowerShell 假定 exiftool 的输出是 ASCII,并将其转换为 Unicode,从而破坏了输出。

与此相关的网页:
https://brianreiter.org/2010/01/29/powershells-object-pipeline-corrupts-piped-binary-data/
https://blogs.msdn.microsoft.com/sergey_babkins_blog/2016/12/29/un-messing-unicode-in-powershell/

总之,命令本身没有问题,问题在于 Powershell 对原始二进制数据的处理。在 CMD 中运行命令会产生预期的输出。

相关内容