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

Issue editing larger images from Camera snapshot in HA (Error: unknown JPEG marker 0) #55

Open
Joncole2k opened this issue Dec 26, 2024 · 0 comments

Comments

@Joncole2k
Copy link

I started working with node red specifically for this image tools. Currently I have several HA automations based on sensors that send push notifications based on security camera motion alerts. But certain 'wide angle' views would be better to be sent cropped first at specific trigger event points. So I planned on using node red to do the same automation, watch for sensor, take snapshot, crop image, send cropped image.

My cameras are 4k so pixel size is 3840 x 2160 on HA > Camera > Take Snapshot.

After using node red to taking the snapshot and trying to crop the image, I kept running into errors and issues after the snapshot was taken. I tried passing the image in the buffer msg and I tried saving the image and loading the image. [at first I found out the node red issue with the URL/directory of HA, which I resolved by using 'homeassistant' instead of 'config' in the path, which solved some issues but still ran into image processing errors.] I started to assume it might be size issue, so I cropped several versions and found that the smaller versions could run without issue.

I have separated out just the image processing part to narrow down the issue since I can trigger the camera snapshot without issue.

When I run this flow, using the original file created by the HA snapshot I get this error: "Error: unknown JPEG marker 0"
The same flow runs fine on 2 different versions that I downloaded, cropped smaller, and reuploaded to the same directory.

Is this an issue with the large file size of the image being too big or is this an issue somehow with the way HA snapshot saves the jpg? (I could try to down sample the camera snapshot or use the smaller substream image but I needed the HD original since after cropping I would lose size and detail anyways.)

image

    {
        "id": "5062a22cba947355",
        "type": "inject",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "props": [
            {
                "p": "payload",
                "v": "true",
                "vt": "bool"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 65,
        "y": 660,
        "wires": [
            [
                "4b4336d4cb19e7ae",
                "8ec85399b53712a1",
                "3a771436fea9d1b6"
            ]
        ],
        "l": false
    },
    {
        "id": "4b4336d4cb19e7ae",
        "type": "jimp-image",
        "z": "e1c8e6c6bf7c788c",
        "name": "Load cropped 11",
        "data": "/homeassistant/www/images/snapshots/store/store poe/test11.jpg",
        "dataType": "str",
        "ret": "img",
        "parameter1": "",
        "parameter1Type": "msg",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "payload",
        "parameterCount": 0,
        "jimpFunction": "none",
        "selectedJimpFunction": {
            "name": "none",
            "fn": "none",
            "description": "Just loads the image.",
            "parameters": []
        },
        "x": 240,
        "y": 780,
        "wires": [
            [
                "f504fd9e31561a91"
            ]
        ]
    },
    {
        "id": "f504fd9e31561a91",
        "type": "image viewer",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "width": "500",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 400,
        "y": 780,
        "wires": [
            []
        ]
    },
    {
        "id": "8ec85399b53712a1",
        "type": "jimp-image",
        "z": "e1c8e6c6bf7c788c",
        "name": "Crop resaved",
        "data": "/homeassistant/www/images/snapshots/store/store poe/test1a.jpg",
        "dataType": "str",
        "ret": "img",
        "parameter1": "2733",
        "parameter1Type": "num",
        "parameter2": "175",
        "parameter2Type": "num",
        "parameter3": "576",
        "parameter3Type": "num",
        "parameter4": "324",
        "parameter4Type": "num",
        "parameter5": "",
        "parameter5Type": "",
        "parameter6": "",
        "parameter6Type": "",
        "parameter7": "",
        "parameter7Type": "",
        "parameter8": "",
        "parameter8Type": "",
        "sendProperty": "payload",
        "parameterCount": 4,
        "jimpFunction": "crop",
        "selectedJimpFunction": {
            "name": "crop",
            "fn": "crop",
            "description": "crop to the given region",
            "parameters": [
                {
                    "name": "x",
                    "type": "num",
                    "required": true,
                    "hint": "the x coordinate to crop form"
                },
                {
                    "name": "y",
                    "type": "num",
                    "required": true,
                    "hint": "the y coordinate to crop form"
                },
                {
                    "name": "w",
                    "type": "num",
                    "required": true,
                    "hint": "the width of the crop region"
                },
                {
                    "name": "h",
                    "type": "num",
                    "required": true,
                    "hint": "the height of the crop region"
                }
            ]
        },
        "x": 430,
        "y": 680,
        "wires": [
            [
                "24e86e86a3ee4d58",
                "212a8a5d67f1486b"
            ]
        ],
        "icon": "font-awesome/fa-image"
    },
    {
        "id": "24e86e86a3ee4d58",
        "type": "image viewer",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "width": "500",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 670,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "212a8a5d67f1486b",
        "type": "jimp-image",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "ret": "img",
        "parameter1": "/homeassistant/www/images/snapshots/store/store poe/cropped1.jpg",
        "parameter1Type": "str",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "payload",
        "sendPropertyType": "msg",
        "parameterCount": 1,
        "jimpFunction": "write",
        "selectedJimpFunction": {
            "name": "write",
            "fn": "write",
            "description": "Write to file. NOTE: You can specify an alternative file extension type to change the type. Currently support types are jpg, png, bmp.",
            "parameters": [
                {
                    "name": "filename",
                    "type": "str",
                    "required": true,
                    "hint": "Name of the file",
                    "defaultType": "str"
                }
            ]
        },
        "x": 670,
        "y": 720,
        "wires": [
            []
        ]
    },
    {
        "id": "3a771436fea9d1b6",
        "type": "jimp-image",
        "z": "e1c8e6c6bf7c788c",
        "name": "Crop original",
        "data": "/homeassistant/www/images/snapshots/store/store poe/fm_front1.jpg",
        "dataType": "str",
        "ret": "img",
        "parameter1": "2733",
        "parameter1Type": "num",
        "parameter2": "175",
        "parameter2Type": "num",
        "parameter3": "576",
        "parameter3Type": "num",
        "parameter4": "324",
        "parameter4Type": "num",
        "parameter5": "",
        "parameter5Type": "",
        "parameter6": "",
        "parameter6Type": "",
        "parameter7": "",
        "parameter7Type": "",
        "parameter8": "",
        "parameter8Type": "",
        "sendProperty": "payload",
        "parameterCount": 4,
        "jimpFunction": "crop",
        "selectedJimpFunction": {
            "name": "crop",
            "fn": "crop",
            "description": "crop to the given region",
            "parameters": [
                {
                    "name": "x",
                    "type": "num",
                    "required": true,
                    "hint": "the x coordinate to crop form"
                },
                {
                    "name": "y",
                    "type": "num",
                    "required": true,
                    "hint": "the y coordinate to crop form"
                },
                {
                    "name": "w",
                    "type": "num",
                    "required": true,
                    "hint": "the width of the crop region"
                },
                {
                    "name": "h",
                    "type": "num",
                    "required": true,
                    "hint": "the height of the crop region"
                }
            ]
        },
        "x": 200,
        "y": 840,
        "wires": [
            [
                "45cad9ef2f272c28",
                "a6981d106e11ddde"
            ]
        ],
        "icon": "font-awesome/fa-image"
    },
    {
        "id": "45cad9ef2f272c28",
        "type": "image viewer",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "width": "500",
        "data": "payload",
        "dataType": "msg",
        "active": true,
        "x": 220,
        "y": 920,
        "wires": [
            []
        ]
    },
    {
        "id": "a6981d106e11ddde",
        "type": "jimp-image",
        "z": "e1c8e6c6bf7c788c",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "ret": "img",
        "parameter1": "/homeassistant/www/images/snapshots/store/store poe/market_cropped.jpg",
        "parameter1Type": "str",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "payload",
        "sendPropertyType": "msg",
        "parameterCount": 1,
        "jimpFunction": "write",
        "selectedJimpFunction": {
            "name": "write",
            "fn": "write",
            "description": "Write to file. NOTE: You can specify an alternative file extension type to change the type. Currently support types are jpg, png, bmp.",
            "parameters": [
                {
                    "name": "filename",
                    "type": "str",
                    "required": true,
                    "hint": "Name of the file",
                    "defaultType": "str"
                }
            ]
        },
        "x": 220,
        "y": 960,
        "wires": [
            []
        ]
    }
]```


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant