尼康Zf的Raw文件在immich以及MT Photos上的问题临时解决方案

     之前一直用的尼康工坊、Google Photos、Lightroom来查看相机的Raw格式图片,没有遇到问题,现在要切换成immich或者MT Photos,就碰到了图片异常的问题,MT Photos已经解决了默认缩略图和预览图的显示问题,但是高清预览图没解决,不知道何时会处理。immich可以通过选项解决缩略图和预览图问题,但是头像异常,目前还没解决。既然已经影响到使用了,就只能想着如何解决现状,于是就开始参考immich的方法,首先自己处理Raw格式文件,获取内嵌jpg,然后两个相册不再使用Raw文件,Raw只用来处理提取jpg以及备份,相册使用提取的jpg作为原图,同时相册的网页和app端都开启优先显示原图,原图的大小目前能接受。

    其间尝试了各种提取方案,最终使用dcraw,于是在pve中创建ct给dcraw独立使用,挂载nfs,创建一个shell文件process_new_files.sh用于监控NikonRaw的新文件,然后获取jpg保存到对应的目录

#!/bin/bash


# 源目录和目标目录

SOURCE_DIR="/mnt/nfs_share/NikonRaw"

TARGET_DIR="/mnt/nfs_share/NikonJpg"


# 确保目标目录存在

mkdir -p "$TARGET_DIR"


# 转换函数

convert_to_jpg() {

    local input_file=$1

    local output_file=$2


    # 使用 dcraw 转换 NEF 文件为 JPG

    if dcraw -e -c "$input_file" > "$output_file"; then

        echo "Successfully converted: $input_file -> $output_file"


        # 继承 EXIF 信息

        exiftool -tagsFromFile "$input_file" -DateTimeOriginal -CreateDate -TimeZone -overwrite_original "$output_file"

        if [ $? -eq 0 ]; then

            echo "EXIF data updated: $output_file"

        else

            echo "Failed to update EXIF data: $output_file"

        fi

    else

        echo "Failed to convert: $input_file"

    fi

}


# 监控新文件

inotifywait -m -e create -e moved_to --format '%w%f' "$SOURCE_DIR" | while read -r new_file; do

    if [[ "$new_file" == *.NEF ]]; then

        output_file="$TARGET_DIR/$(basename "${new_file%.NEF}.jpg")"

        convert_to_jpg "$new_file" "$output_file"

    fi

done

    由于提取的jpg中缺少CreateDate会导致immich的图片日期显示错误,所以加了exiftool来处理exif信息,加TimeZone是因为immich处理时会报错,但是不影响使用。

    已有图片的话可以参考下面的文件 process_existing_files.sh

#!/bin/bash


# 源目录和目标目录

SOURCE_DIR="/mnt/nfs_share/NikonRaw"

TARGET_DIR="/mnt/nfs_share/NikonJpg"


# 确保目标目录存在

mkdir -p "$TARGET_DIR"


# 转换函数

convert_to_jpg() {

    local input_file=$1

    local output_file=$2


    # 检查目标文件是否已经存在,避免重复处理

    if [ -f "$output_file" ]; then

        echo "File already converted: $output_file"

        return

    fi


    # 使用 dcraw 转换 NEF 文件为 JPG

    if dcraw -e -c "$input_file" > "$output_file"; then

        echo "Successfully converted: $input_file -> $output_file"


        # 继承 EXIF 信息

        exiftool -tagsFromFile "$input_file" -DateTimeOriginal -CreateDate -TimeZone -overwrite_original "$output_file"

        if [ $? -eq 0 ]; then

            echo "EXIF data updated: $output_file"

        else

            echo "Failed to update EXIF data: $output_file"

        fi

    else

        echo "Failed to convert: $input_file"

    fi

}


# 扫描并处理现有文件

echo "Processing existing files in $SOURCE_DIR..."

find "$SOURCE_DIR" -type f -name "*.NEF" | while read -r file; do

    output_file="$TARGET_DIR/$(basename "${file%.NEF}.jpg")"

    convert_to_jpg "$file" "$output_file"

done

echo "Existing files processed."


    然后给两个文件都加上运行权限

chmod +x process_new_files.sh

chmod +x process_existing_files.sh

    process_existing_files.sh就运行一次就不需要加后台开机启动,process_new_files.sh的话可以添加文件/etc/systemd/system/process_new_files.service

[Unit]

Description=Process new NEF files in NikonRaw directory

After=network.target


[Service]

ExecStart=/root/process_new_files.sh

WorkingDirectory=/root/

StandardOutput=journal

StandardError=journal

Restart=always

User=root

Group=root


[Install]

WantedBy=multi-user.target

然后运行如下命令

systemctl daemon-reload

systemctl enable process_new_files.service

systemctl start process_new_files.service


评论

此博客中的热门博文

飞牛私有云OS相册、MT Photos、immich简单对比

飞牛私有云OS相册、MT Photos、immich简单对比二

N150使用核显的硬件加速功能