The reason I think Lua might come in handy is because of the get_movie_status command in Lua... I would love to be able to run a loop waiting for the return of that function to become 4 (recording in process), and as soon as it sees that recording is in process, then the audio will start recording. This is simply because I can get the audio recording to start almost automatically, and the video takes about a second to actually start recording.
I guess my question is this: Is there an easy way to do this using my Python program? Or would the simplest way be to use Lua?
Finding out when video started in chdkptp is easy enough, but with your current setup getting the information back to your python program may be tricky.
To wait for video to start recording, you could use something like
click('video') repeat sleep(10) until get_video_status() == 4
(note all code in this post is off the top of my head, untested, may contain typos)
If you wan to start audio recording from within lua, you could use os.execute (
http://www.lua.org/manual/5.2/manual.html#6.9) to execute an external command, or io.popen (
http://www.lua.org/manual/5.2/manual.html#6.8) to start a program you can send output to later.
Assuming you have some command 'start_audio_recording', you could do it something like this:
!con:execwait([[click('video') repeat sleep(10) until get_video_status() == 4]]) os.execute('start_audio_recording')
If you were using the popen method, you'd do some thing like
!ph=io.open('some_program','w')
once on startup, and then use ph:write() to send to that programs standard input.
If you want to do it with python, you need a way to communicate back from chdkptp to your python program. You could start chdkptp as a subprocess instead of piping from the shell, but handling both stdin and stdout can be tricky. For a quick and dirty hack, you could just make chdkptp create a file that you can look for with python, e.g.
!con:execwait([[click('video') repeat sleep(10) until get_video_status() == 4]]) fh=io.open('video_recording','wb') fh:close()
then check for video_recording existing in your python script, and remove it.
A follow up question is this: Is there an easy way for me to find the delay between when I send the "=click('video')/n" command and when the camera actually starts recording to simply find that delay and figure out if it is constant?
To return the number of milliseconds it took for get_video_status() to become 4, use something like
=t0=get_tick_count() click('video') repeat sleep(10) until get_video_status() == 4 return get_tick_count()-t0
I wouldn't expect to be exactly constant since the camera tries to autofocus before starting and that takes a variable amount of time. If your camera has dedicated video mode that can start recording with the shutter button, you could probably get a more consistent delay by having the script hold half press for a fixed amount of time and then press play, e.g.
press'shoot_half' sleep(500) click'shoot_full'
This gives the camera a fixed half second to focus before starting. I'm not aware of a way to do this on cameras that only let you start with the video button.