Detect motion while recording movie - Workaround - General Discussion and Assistance - CHDK Forum  

Detect motion while recording movie - Workaround

  • 4 Replies
  • 284 Views
Detect motion while recording movie - Workaround
« on: 05 / May / 2022, 13:35:04 »
Advertisements
Hey! I'm new to CHDK, been hacking for just a few days with my SX60HS.

Sorry if this issue was still addressed here (it probably was), but I could not find the topic.

I found that (at least for this camera) it is not possible to detect motion while recording a movie, because the camera prevents access to the filesystem during video recording and the motion detection module fails to load.

I don't know whether there is an official way to do this, but the workaround I found was to make the motion detection module never unload from memory (by making _module_can_unload() return always  false). This way, I just need to make a dummy call to md_detect_motion() before start recording in order to load the module and then I can use motion detection during recording.

 
Code: [Select]
int _module_can_unload()
 {
-    return camera_info.state.state_kbd_script_run == SCRIPT_STATE_INACTIVE;
+    return 0; //camera_info.state.state_kbd_script_run == SCRIPT_STATE_INACTIVE;
 }

Any thoughts?
Thanks,

*

Offline Caefix

  • *****
  • 887
  • Sorry, busy deleting test shots...
Re: Detect motion while recording movie - Workaround
« Reply #1 on: 05 / May / 2022, 15:46:17 »
 :) Just as a starting point for experimental scripting:
I have never tried to combine it with video, but it seems possible:  :lol
Start script, adjust grid with zoom, exit <alt>, start video, enter <alt>...


All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 13792
Re: Detect motion while recording movie - Workaround
« Reply #2 on: 05 / May / 2022, 22:10:35 »
I found that (at least for this camera) it is not possible to detect motion while recording a movie, because the camera prevents access to the filesystem during video recording and the motion detection module fails to load.
What's the specific error? Do you have "Enable Unsafe IO" checked in miscellaneous?

Attempting to test this on elph180, I got errors related fopen from Lua script, but not the md module. I was able to run motion.bas after starting video recording. Without "Enable Unsafe IO", loading ubasic.flt failed.

Quote
I don't know whether there is an official way to do this, but the workaround I found was to make the motion detection module never unload from memory (by making _module_can_unload() return always  false). This way, I just need to make a dummy call to md_detect_motion() before start recording in order to load the module and then I can use motion detection during recording.
It seems like you shouldn't need a C code change if you do the dummy call and then start video recording within the same script.
Don't forget what the H stands for.

Re: Detect motion while recording movie - Workaround
« Reply #3 on: 06 / May / 2022, 14:00:01 »
Quote
What's the specific error? Do you have "Enable Unsafe IO" checked in miscellaneous?
Did not try this, but it should work since it overrides the semaphore that causes the module load to hang. I'll try this later.

Quote
It seems like you shouldn't need a C code change if you do the dummy call and then start video recording within the same script.
You're absolutely right. I was issuing individual lua commands via ptp, so it did not work without the FW patch. Running all the code within the same script made the trick. Thank you!


*

Offline reyalp

  • ******
  • 13792
Re: Detect motion while recording movie - Workaround
« Reply #4 on: 06 / May / 2022, 14:47:01 »
Quote
What's the specific error? Do you have "Enable Unsafe IO" checked in miscellaneous?
Did not try this, but it should work since it overrides the semaphore that causes the module load to hang. I'll try this later.
I think it should work for PTP. From my testing, doesn't work for Lua scripts on the camera, because Lua uses fopen rather than open, and "Unsafe IO" option doesn't allow fopen to work.

Note that Lua using fopen means a PTP script that uses Lua require or other Lua file IO will also fail when video is recording.
Quote
I was issuing individual lua commands via ptp, so it did not work without the FW patch. Running all the code within the same script made the trick. Thank you!
That makes sense. If you need execute multiple things in a script with interactive control, you can use rlibs msg_shell as a starting point.
Don't forget what the H stands for.

 

Related Topics