Closed denven closed 5 months ago
Both these settings:
Both these settings:
However, it may not take effect since I am enabling both, I just checked.
"Snapshot" option enable/disable all snapshot features. "Snapshot for recorded video" enable/disable the creation of the thumbnails for the recorded video. I know, it's not a very proper name, but the thumbnail for the cam is like a snapshot.
So, if you want to enable the thumbnails you need to enable both options.
No jpg files when both items are enabled.
Strange...
Try to run the process manually:
/tmp/sd/yi-hack/script/thumb.sh cron
Probably there is an error.
@roleoroleo I did some checks based on your advice.
/home/yi-hack # cat etc/system.conf | grep -e ^SNAPSHOT.*=yes
SNAPSHOT=yes
SNAPSHOT_VIDEO=yes
/home/yi-hack # cat /var/spool/cron/crontabs/root
* * * * * /home/yi-hack/script/thumb.sh cron
0 * * * * sleep 20; /home/yi-hack/script/clean_records.sh 90
/home/yi-hack # tail -f -n5 /tmp/thumb.log
2023-05-07 [01-10-00] [INFO] === SERVICE START ===
2023-05-07 [01-10-00] [WARN] Adjusting folder permissions to 0755 ...
2023-05-07 [01-10-01] [INFO] checkFiles
2023-05-07 [01-10-01] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4].
2023-05-07 [01-10-01] [INFO] === SERVICE STOPPED ===
/home/yi-hack # cat /tmp/thumb.log | grep "jpg FAILED" 2023-05-07 [00-40-01] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4]. 2023-05-07 [00-41-01] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4]. 2023-05-07 [00-42-03] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4]. 2023-05-07 [00-43-01] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4]. 2023-05-07 [00-44-02] [ERROR] checkFiles: create jpg FAILED - [/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4]
> **So far, I know the `thumb.sh` which is used to snapshot image files doesn't work properly. Although it runs every minute, it fails each time as well, no image files will be generated.**
### More investigations on the reason for the failures
- check the script `thumb.sh` source code, and find these code lines
```bash
minimp4_yi -t 1 $file $BASE_NAME.h26x
imggrabber -f $BASE_NAME.h26x -r low -w > $BASE_NAME.jpg
/home/yi-hack # find / -type f -name minimp4_yi -o -name imggrabber
/home/yi-hack/bin/imggrabber
/home/yi-hack/bin/minimp4_yi
/home/yi-hack # ls /tmp/sd/record/2023Y05M02D10H/50M59S01.mp4
/tmp/sd/record/2023Y05M02D10H/50M59S01.mp4
/home/yi-hack #cd /tmp/sd/record/2023Y05M02D10H/
/tmp/sd/record/2023Y05M02D10H # minimp4_yi -t 1 50M59S01.mp4 50M59S01.h26x /tmp/sd/record/2023Y05M02D10H # imggrabber -f 50M59S01.h26x -r low -w > 50M59S01.jpg watermark on /tmp/sd/record/2023Y05M02D10H # echo $? 250 /tmp/sd/record/2023Y05M02D10H # ls 50M59S01.* 50M59S01.h26x 50M59S01.jpg 50M59S01.mp4
> From the above, the image file is generated, I downloaded it and found it is not viewable.
- Check the original video file:
> **The original video file 50M59S01.mp4 is only 204.2K which is not a complete one-minute video file, the .h26x file is 24 bytes, and the generated image file is an empty one.**
```bash
/tmp/sd/record/2023Y05M02D10H # ls -l -hk 50M59S01.*
-rwx------ 1 root 0 24 May 7 03:01 50M59S01.h26x
-rwx------ 1 root 0 0 May 7 12:14 50M59S01.jpg
-rwx------ 1 root 0 204.2K May 2 03:51 50M59S01.mp4
imggrabber
and run it again:
/tmp/sd/record/2023Y05M02D10H # imggrabber -d -f 50M59S01.h26x -r low -w > 50M59S01.jpg
debug on
watermark on
Starting program
The size of the file is 24
No frame found
/tmp/sd/record/2023Y05M02D10H # echo $?
250
The C program imggrabber.c
has an exit code -6 when it knows "No frame found" since the Shell $? (the exit code for the last command) range is always non-negative, and is treated modulo 256, then -6 will be converted to 250.
else {
if (debug) fprintf(stderr, "No frame found\n");
return -6;
}
As we can see an empty snapshot has been generated with an error no 250, and the script thumb.sh
then exits after logging the error.
echo "${L_FILE_LIST}" | while read file; do
...
if [ $? -ne 0 ]; then
logAdd "[ERROR] checkFiles: create jpg FAILED - [${file}]."
rm -f $BASE_NAME.h26x
rm -f $BASE_NAME.jpg
return 0 # line 102
fi
....
done
So the fact is each time when it fails on some file and exits, it will continue to fail and exit on the same file again, and it will not move on to the newer or other files.
I think the video file is very likely to turn out to be incomplete or corrupted at the time the camera reboots or shutdowns, the imggrabber
may always fail to take a snapshot from an incomplete h26x file, which results in the script thumb.sh
interrupting at the same file.
imggrabber
fails to grab a frame image.
echo "${L_FILE_LIST}" | while read file; do
...
minimp4_yi -t 1 $file $BASE_NAME.h26x
if [ $? -ne 0 ]; then
logAdd "[ERROR] checkFiles: demux mp4 FAILED - [${file}]."
rm -f $BASE_NAME.h26x
# return 0
continue
fi
imggrabber -f $BASE_NAME.h26x -r low -w > $BASE_NAME.jpg
if [ $? -ne 0 ]; then
logAdd "[ERROR] checkFiles: create jpg FAILED - [${file}]."
rm -f $BASE_NAME.h26x
rm -f $BASE_NAME.jpg
# return 0
continue
fi
....
done
/tmp/sd/record # cd 2023Y05M07D09H/
/tmp/sd/record/2023Y05M07D09H # ls
06M02S58.jpg 07M00S60.jpg 26M56S03.jpg 27M00S60.jpg 28M00S60.jpg 39M18S42.jpg 40M00S60.jpg 43M20S40.jpg 44M00S60.jpg 51M24S36.jpg 52M00S60.jpg
06M02S58.mp4 07M00S60.mp4 26M56S03.mp4 27M00S60.mp4 28M00S60.mp4 39M18S42.mp4 40M00S60.mp4 43M20S40.mp4 44M00S60.mp4 51M24S36.mp4 52M00S60.mp4
And there is a performance issue in the thumb.sh
script since it runs every minute with repetitive checks of all existing files.
For example, my SD card storage is 32GB, and one video file is around 10MB, then the number of video files will be accumulated to 3,000+ before the SD card storage exhausts or is cleaned, the more files accumulated in the SD card, the more performance cost will take. This is not favorable.
To enhance, we can change it to check the single latest file which hasn't been generated with a snapshot file, via a timestamp close (1-2 minutes earlier) to its run time to save resources. Most likely, all the new files generated after the time feature is enabled will be captured with the snapshots.
The failures from incomplete or corrupted files cannot be recovered and then can be ignored.
Thank you for your analysis. I will change the script asap.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi, @roleoroleo
The feature is enabled by default when I hacked with the completely new firmware, but it was disabled after some time of use or configuration changes. I've no idea which item will switch the video thumbnail feature.
Can you tell me about this? Thanks