roleoroleo / yi-hack-MStar

Custom firmware for Yi 1080p camera based on MStar platform
GNU General Public License v3.0
847 stars 112 forks source link

Which configuration item will disable the thumbnail feature of video files? #503

Closed denven closed 5 months ago

denven commented 1 year ago

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

image

roleoroleo commented 1 year ago

Both these settings: immagine

denven commented 1 year ago

Both these settings: immagine

However, it may not take effect since I am enabling both, I just checked.

roleoroleo commented 1 year ago

"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.

denven commented 1 year ago

No jpg files when both items are enabled.

image

image

roleoroleo commented 1 year ago

Strange... Try to run the process manually: /tmp/sd/yi-hack/script/thumb.sh cron Probably there is an error.

denven commented 1 year ago

@roleoroleo I did some checks based on your advice.

Check configurations, failures or logs

/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 # 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

/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

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.

denven commented 1 year ago

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.

roleoroleo commented 1 year ago

Thank you for your analysis. I will change the script asap.

github-actions[bot] commented 6 months ago

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.