Timestamped Videos - Script Writing - CHDK Forum supplierdeeply

Timestamped Videos

  • 7 Replies
  • 1760 Views
*

Offline Davo

  • ***
  • 176
Timestamped Videos
« on: 27 / April / 2013, 07:35:28 »
Advertisements
Hi,

The script below will record a series of video clips (.MOV) and then change each clip name to the day and time when the clip started - e.g. 26152534.MOV (15:25:34 on the 26th). The only variable is 's' which is the individual clip length in seconds.

I wrote it to record solar events so I have my camera time set to UTC time (GMT without daylight saving). This means I can accurately time any flares that I capture in astro time.

I run it on my camera attached to a remotely controlled telescope that I control from inside my garage. The camera is controlled from inside CHDKPTP which allows me to focus remotely on the LiveView screen.

One question for the gurus: I can start the script remotely by typing

luar s=10; loadfile('A/CHDK/SCRIPTS/SUNVIDZ.LUA')()

into the Execute text box. Any idea how I can stop it remotely so I can change the telescope target?


Code: [Select]
--[[
@title Timestamped Videos by Davo
@param s Seconds per clip
@default s 10
--]]

sleep ( 2000 )
clip_length = s

-- Functions
function get_current_folder()
dir = os.listdir("A/DCIM", false)
count = table.getn(dir)
return(dir[count])
end

function get_last_clip_name()
dir = os.listdir("A/DCIM/" .. get_current_folder(), false)
count = table.getn(dir)
return(dir[count])
end -- end of get_last_clip_name()

function rename_file(new_name)
clip_name = get_last_clip_name()
file_name_old = "A/DCIM/" .. get_current_folder() .. "/" .. clip_name
file_name_new = "A/DCIM/" .. get_current_folder() .. "/" .. new_name .. ".MOV"
os.rename(file_name_old, file_name_new)
end

function record_clip( secs )
press("video")
sleep(2000)
release("video")
sleep ( 1000 * secs )
press("video")
sleep(2000)
release("video")
end

function restore()
if get_movie_status() == 4 then
post_levent_to_ui('PressMovieButton')
end
print("User stopped script")
end

repeat
md = get_time("D")
mh = get_time("h")
mm = get_time("m")
ms = get_time("s")
start_time = string.format("%02d%02d%02d%02d", md, mh, mm, ms)
record_clip ( clip_length )
sleep(1000)
rename_file(start_time)
until false

*

Offline reyalp

  • ******
  • 12690
Re: Timestamped Videos
« Reply #1 on: 27 / April / 2013, 15:43:15 »
Quote
into the Execute text box. Any idea how I can stop it remotely so I can change the telescope target?

You can do this using the message interface. See http://chdk.wikia.com/wiki/Lua/PTP_Scripting

in your repeat loop, do something like
Code: [Select]
m=read_usb_msg()
...
repeat until m == 'quit'
Then from your ptp client use
Code: [Select]
putm quit
when you want to end the script. You will probably want to call your restore() function manually at the end of the script, since it is only triggered when you interrupt with key press.

Note that you could just start the script once and use messages to do all the control, see lua/rlibs msg_shell in the chdkptp source ( http://trac.assembla.com/chdkptp/browser/trunk/lua/rlibs.lua#L990 ) for an example of a message controlled script.

FYI, I did some investigation of how the camera deals with timestamps here: http://chdk.wikia.com/wiki/Camera_timestamps you may find this useful if you are converting between camera time and real time.
Don't forget what the H stands for.

*

Offline Davo

  • ***
  • 176
Re: Timestamped Videos
« Reply #2 on: 28 / April / 2013, 10:56:46 »
Progress! I changed my repeat loop as per your suggestion to

Code: [Select]
repeat
ptp_message = read_usb_msg()
if ptp_message == 'quit' then
restore()
break
end
md = get_time("D")
mh = get_time("h")
mm = get_time("m")
ms = get_time("s")
start_time = string.format("%02d%02d%02d%02d", md, mh, mm, ms)
record_clip ( clip_length )
sleep(1000)
rename_file(start_time)
until false

I can now stop the script by sending
Code: [Select]
putm quit.

One thing I noticed is that I need to send

Code: [Select]
lua s=10; loadfile('A/CHDK/SCRIPTS/SUNVIDZ.LUA')()
instead of

Code: [Select]
luar s=10; loadfile('A/CHDK/SCRIPTS/SUNVIDZ.LUA')()
if I want to see the LiveView while the script is running.

I am now going to try to add some buttons to CHDKPTP to start and stop the script and maybe a numeric input box to adjust the variable s (clip length in seconds).

Thanks for your help - all I need now is some Sun.

ps Very interesting that the camera works in UTC. It's almost as if Canon designed it for astronomy.


*

Offline reyalp

  • ******
  • 12690
Re: Timestamped Videos
« Reply #3 on: 28 / April / 2013, 15:48:32 »
Code: [Select]
lua s=10; loadfile('A/CHDK/SCRIPTS/SUNVIDZ.LUA')()
instead of

Code: [Select]
luar s=10; loadfile('A/CHDK/SCRIPTS/SUNVIDZ.LUA')()
Oops, I should have mentioned that. You need this because luar waits for the script to end, but in this case you just want to fire off the script without waiting.

Quote
ps Very interesting that the camera works in UTC. It's almost as if Canon designed it for astronomy.
The camera doesn't exactly work in UTC, it just ignores timezones completely. In Unix style system the "epoch" is 00:00 Jan 1 1970 UTC, and local time derived from that using timezone files that need updating when countries fiddle with their DST rules. On the camera, the epoch is effectively 00:00 Jan 1 1970 in whatever timezone the camera is using. This means the camera doesn't have to know anything about timezones (except for the "alternate" timezone feature, which is just an offset), but it also means the timestamp isn't an absolute reference. The camera gets away from the DST update problem by requiring you to manually select DST or not.

If you set your camera to UTC the timestamp will be equivalent to a Unix timestamp, which may convenient.

FWIW, if you want to keep set your camera time in sync with your PC to keep it from drifting too far, you can find some info in this thread: http://chdk.setepontos.com/index.php?topic=7280.msg78087#msg78087
Don't forget what the H stands for.


*

Offline Davo

  • ***
  • 176
Re: Timestamped Videos
« Reply #4 on: 29 / April / 2013, 09:57:40 »
Quote
Oops, I should have mentioned that.

That was my bad because you have explained that before to me. Too much going on.

Anyhoos, I managed to hack the CHDKPTP gui.lua file to give me the control I wanted. I now have a RunVidz and StopVidz button to start and stop my script as well as a number spinner to select the clip time in seconds. It's not very elegant but it does the job.

I have attached it together with the matching script in case they are of use to others.

My next mod will be add a button to sync to my PC clock which is itself linked to a UTC time service.

*

Offline Davo

  • ***
  • 176
Re: Timestamped Videos
« Reply #5 on: 01 / May / 2013, 06:06:04 »
Here is a sample of what I will be using this script for.

This was taken on a 4" telescope and started as a 15 second clip that I processed in AviStack and Gimp. Eventually, I will produce animations to show the surface movement of the Sun.

*

Offline blackhole

  • *****
  • 778
  • A590IS 101b
    • Planetary astrophotography
Re: Timestamped Videos
« Reply #6 on: 02 / May / 2013, 01:55:27 »
Quote
Here is a sample of what I will be using this script for.

Good job!

*

Offline Davo

  • ***
  • 176
Re: Timestamped Videos
« Reply #7 on: 02 / May / 2013, 08:38:30 »
Thanks for that. I did a comparison today with my £300 TIS astrocam. It is not really like for like because the sunspot group has evolved and the seeing conditions were different.  However,  I think the £50 A810 is just as good and it even seems to pick out the solar granulation cells better.

btw, I found a better way to use my script to record video sequences. With my script, the camera takes around 5 seconds to stop and start recording between clips which means I lose a lot of frames. What I do now is record 4GB clips (~14 minutes) and then chop them up into smaller clips using the VirtualDub 'Save segmented AVI' feature. This way, I only lose 5s of video every 14 minutes. I can also adjust the length of the individual cliplets to suit conditions.


 

Related Topics