ScarShow

< IS >

使用 Exiftool 管理手動鏡頭資訊

由於長期都使用手動鏡頭在攝影,而手動鏡頭因為透過轉接的方式,機身基本上都紀錄不到正確的鏡頭資訊。

平常是用 Windows 來管理照片,所以這幾年都是使用 AnalogExif 來修改鏡頭資訊,但它好幾年都沒有更新了,在使用上有總有些痛點,所以帶來了不少的麻煩。

而最近受惠於 WSL 的成熟,現在在 Windows 系統上我可以繼續使用 Linux 來開發程式,所以既然能在 Windows 上使用 Linux 那麼我何不自己寫支程式來管理大量相片的鏡頭資訊?

所以我就找了強大的 exiftool 指令作為基底寫一支批次管理程式。

安裝

如果是使用 Ubuntu 的話就用下面指令就能安裝了。

sudo apt install exiftool

macOS 的話先去裝 Homebrew 再用下面指令安裝。

brew install exiftool

如果是其它平台理論上都會有相應的指令可供安裝。

使用

基本上 Exiftool 非常強大,只要有支援圖檔都能夠進行操作,雖然它還有其它的功能,但管理資訊則只需要專注在讀跟寫資訊就好。

讀取資訊

我們可以用以下的指令將照片中的資訊讀取出來,這邊額外的參數 -s 能讓屬性以短名稱的方式以及 -g 按照分類呈現,這樣有助於後續的程式撰寫。

exiftool -s -g ~/SCR06780.jpg

---- ExifTool ----
ExifToolVersion                 : 12.40
Warning                         : [minor] Fixed incorrect URI for xmlns:MicrosoftPhoto
---- File ----
FileName                        : SCR06780.jpg
Directory                       : /home/scarwu
FileSize                        : 14 MiB
FileModifyDate                  : 2022:04:26 12:00:52+08:00
FileAccessDate                  : 2022:09:14 10:52:53+08:00
FileInodeChangeDate             : 2022:09:14 10:52:53+08:00
FilePermissions                 : -rw-r--r--
FileType                        : JPEG
FileTypeExtension               : jpg
MIMEType                        : image/jpeg
ExifByteOrder                   : Little-endian (Intel, II)
CurrentIPTCDigest               : 07b9982d1d3b65db7841f531246a37ad
ImageWidth                      : 5961
ImageHeight                     : 3974
EncodingProcess                 : Baseline DCT, Huffman coding
BitsPerSample                   : 8
ColorComponents                 : 3
YCbCrSubSampling                : YCbCr4:4:4 (1 1)
---- JFIF ----
JFIFVersion                     : 1.01
---- EXIF ----
ImageDescription                :
Make                            : SONY
Model                           : ILCE-7C
XResolution                     : 300
YResolution                     : 300
ResolutionUnit                  : inches
Software                        : Capture One 22 Windows
ExposureTime                    : 1/1000
ExposureProgram                 : Aperture-priority AE
FNumber                         : 2.0
ISO                             : 100
SensitivityType                 : Recommended Exposure Index
RecommendedExposureIndex        : 100
ExifVersion                     : 0230
DateTimeOriginal                : 2022:04:24 18:17:00
CreateDate                      : 2022:04:24 18:17:00
ShutterSpeedValue               : 1/1000
ApertureValue                   : 2.0
BrightnessValue                 : 6.9
ExposureCompensation            : -0.7
MaxApertureValue                : 2.0
MeteringMode                    : Multi-segment
LightSource                     : Unknown
Flash                           : Off, Did not fire
FocalLength                     : 15.0 mm
SubSecTimeOriginal              : 641
SubSecTimeDigitized             : 641
ExifImageWidth                  : 5961
ExifImageHeight                 : 3974
FileSource                      : Digital Camera
SceneType                       : Directly photographed
CustomRendered                  : Normal
ExposureMode                    : Auto
WhiteBalance                    : Auto
DigitalZoomRatio                : 1
FocalLengthIn35mmFormat         : 15 mm
SceneCaptureType                : Standard
Contrast                        : High
Saturation                      : Normal
Sharpness                       : Hard
LensInfo                        : 15mm f/2
LensModel                       : DT 40mm F2.8 SAM
Compression                     : JPEG (old-style)
ThumbnailOffset                 : 836
ThumbnailLength                 : 1600
ThumbnailImage                  : (Binary data 1600 bytes, use -b option to extract)
---- XMP ----
XMPToolkit                      : XMP Core 4.4.0-Exiv2
Rating                          : 2
CreatorTool                     : Capture One 22 Windows
FlashCompensation               : 0
Lens                            : DT 40mm F2.8 SAM
LegacyIPTCDigest                : 59B45D2B487CE598F00B6D2C62ABE236
Description                     :
---- IPTC ----
ApplicationRecordVersion        : 4
DateCreated                     : 2022:04:24
TimeCreated                     : 18:17:00+00:00
DigitalCreationDate             : 2022:04:24
DigitalCreationTime             : 18:17:00+00:00
CodedCharacterSet               : UTF8
Caption-Abstract                :
---- ICC_Profile ----
ProfileCMMType                  : Adobe Systems Inc.
ProfileVersion                  : 2.1.0
ProfileClass                    : Display Device Profile
ColorSpaceData                  : RGB
ProfileConnectionSpace          : XYZ
ProfileDateTime                 : 2000:08:11 19:51:59
ProfileFileSignature            : acsp
PrimaryPlatform                 : Apple Computer Inc.
CMMFlags                        : Not Embedded, Independent
DeviceManufacturer              : none
DeviceModel                     :
DeviceAttributes                : Reflective, Glossy, Positive, Color
RenderingIntent                 : Perceptual
ConnectionSpaceIlluminant       : 0.9642 1 0.82491
ProfileCreator                  : Adobe Systems Inc.
ProfileID                       : 0
ProfileCopyright                : Copyright 2000 Adobe Systems Incorporated
ProfileDescription              : Adobe RGB (1998)
MediaWhitePoint                 : 0.95045 1 1.08905
MediaBlackPoint                 : 0 0 0
RedTRC                          : (Binary data 14 bytes, use -b option to extract)
GreenTRC                        : (Binary data 14 bytes, use -b option to extract)
BlueTRC                         : (Binary data 14 bytes, use -b option to extract)
RedMatrixColumn                 : 0.60974 0.31111 0.01947
GreenMatrixColumn               : 0.20528 0.62567 0.06087
BlueMatrixColumn                : 0.14919 0.06322 0.74457
---- Composite ----
Aperture                        : 2.0
ImageSize                       : 5961x3974
Megapixels                      : 23.7
ScaleFactor35efl                : 1.0
ShutterSpeed                    : 1/1000
SubSecCreateDate                : 2022:04:24 18:17:00.641
SubSecDateTimeOriginal          : 2022:04:24 18:17:00.641
DateTimeCreated                 : 2022:04:24 18:17:00+00:00
DigitalCreationDateTime         : 2022:04:24 18:17:00+00:00
CircleOfConfusion               : 0.030 mm
FOV                             : 54.4 deg
FocalLength35efl                : 35.0 mm (35 mm equivalent: 35.0 mm)
HyperfocalDistance              : 20.39 m
LightValue                      : 12.0
LensID                          : DT 40mm F2.8 SAM

以我所輸出的檔案為例,由於我使用 LM-EA7 做為轉接環所以有一些基本的資訊,但這些資訊基本上都是錯誤的。

除了 File 及 Composite 區塊的屬性,其他大部分的屬性都能夠修改,所以整理一下剛剛讀出的資訊,基本上我們需要調整的屬性有三類:

  1. 鏡頭名稱
    • Lens
    • LensModel
    • LensInfo
    • LensID
  2. 焦段
    • FocalLength
    • FocalLengthIn35mmFormat
  3. 光圈
    • MaxApertureValue
    • ApertureValue
    • FNumber

寫入資訊

有了剛剛的整理好的屬性,我們就能填入正確的參數去調整照片屬性。

SMC Pentax-M 50mm F1.4 這顆鏡頭為例,我們可以用下面的指令去修改照片屬性。

但這邊要注意一下如果攝影的相機不是全幅機的話 FocalLengthIn35mmFormat 這項屬性需要而外進行換算。

然而在拍照的時很難紀錄手動鏡頭當下的光圈值,除非你都會去記錄,所以大部分我都只設定最大光圈 MaxApertureValue 而把 ApertureValueFNumber 清除。

exiftool -overwrite_original \
    -Lens="SMC Pentax-M 50mm F1.4" \
    -LensModel="SMC Pentax-M 50mm F1.4" \
    -LensInfo="50mm f/1.4" \
    -FocalLength="50.0" \
    -FocalLengthIn35mmFormat="50" \
    -MaxApertureValue="1.4" \
    -ApertureValue="" \
    -FNumber="" \
    -LensID="" \
    ~/SCR06780.jpg

這樣你就會得到一張鏡頭資訊正確的照片了!

程式碼

根據剛剛的指令,為了更方便管理照片,我寫了一個 Shell Script 來管理大量的相片,裡面鏡頭的資訊也能夠照情況自由修改。

#!/usr/bin/env bash

case "${1}" in
    zm35)
        export LENS_NAME="Carl Zeiss Distagon T* 35mm F1.4 ZM"
        export FOCAL_LENGTH="35"
        export APERTURE_VALUE="1.4"
        ;;

    km35)
        export LENS_NAME="Konica M-Hexanon 35mm F2"
        export FOCAL_LENGTH="35"
        export APERTURE_VALUE="2"
        ;;

    vm35)
        export LENS_NAME="Voigtlander Nokton Classic 35mm F1.4"
        export FOCAL_LENGTH="35"
        export APERTURE_VALUE="1.4"
        ;;

    vm15)
        export LENS_NAME="Voigtlander Super Wide-Heliar Aspherical III 15mm F4.5"
        export FOCAL_LENGTH="15"
        export APERTURE_VALUE="4.5"
        ;;

    pk50)
        export LENS_NAME="SMC Pentax-M 50mm F1.4"
        export FOCAL_LENGTH="50"
        export APERTURE_VALUE="1.4"
        ;;

    lomo32)
        export LENS_NAME="Lomogon 32mm F2.5 Art Lens"
        export FOCAL_LENGTH="32"
        export APERTURE_VALUE="2.5"
        ;;

    *)
        echo $"Usage: $0 <zm35|km35|vm35|vm15|pk50|lomo32> <?path>"

        exit 1
esac

if [ "" != "${2}" ]; then
    export TARGET_PATH="${2}"
else
    export TARGET_PATH=`pwd`
fi

if [ ! -d "${TARGET_PATH}" ]; then
    echo "Path is't folder or not exists"

    exit 1
fi

echo "Target Path: ${TARGET_PATH}"
echo "Lens Name: ${LENS_NAME}"
echo "Focal Length: ${FOCAL_LENGTH}"
echo "Aperture Value: ${APERTURE_VALUE}"

echo -e "\nIs above information correct? [Y/n] \c"

read ANWSER

if [ "n" == "${ANWSER}" ]; then
    exit 1
fi

echo ""

for FILENAME in "${TARGET_PATH}"/*.jpg; do
    if [ ! -f "${FILENAME}" ]; then
        continue
    fi

    echo "${FILENAME}"

    exiftool -overwrite_original \
        -Lens="${LENS_NAME}" \
        -LensModel="${LENS_NAME}" \
        -XMP-microsoft:LensModel="${LENS_NAME}" \
        -LensInfo="${FOCAL_LENGTH}mm f/${APERTURE_VALUE}" \
        -FocalLength="${FOCAL_LENGTH}.0" \
        -FocalLengthIn35mmFormat="${FOCAL_LENGTH}" \
        -MaxApertureValue="${APERTURE_VALUE}" \
        -ApertureValue="" \
        -FNumber="" \
        -LensID="" \
        "${FILENAME}" 1> /dev/null
done

使用方式為進入你需要調整照片的資料夾,然後呼叫這支程式就會根據你的選擇對你的照片進行修改。

./path/to/exif.sh zm35

# or

alias exif="./path/to/exif.sh"

exif zm35

最新的程式我放在 Gist 上。

References