CHDKPTP File Downloading - General Help and Assistance on using CHDK stable releases - CHDK Forum

CHDKPTP File Downloading

  • 92 Replies
  • 28332 Views
CHDKPTP File Downloading
« on: 06 / November / 2017, 18:54:15 »
Advertisements
Hi everyone!

I made a post back in September and was met with lots of useful feedback.
Post link: https://chdk.setepontos.com/index.php?topic=13246.0

Unfortunately do to time constraints I couldn't download libusb onto all of the camera's in the array and therefor couldn't really follow through with a lot of your suggestions.

I've finally been given the go-ahead to start working on this again and so I've been re-reading a lot of older posts on CHDKPTP. I've successfully connected a few cameras to chdkptp and taken some pictures using the instructions given here https://chdk.setepontos.com/index.php?topic=11490.msg112688#msg112688

I'm super excited to actually have something working like it's supposed to now that I'm starting from scratch and don't have a time limit looming over me.

After taking the pictures I've downloaded them using !mc:download_images() and gotten two folders in my chdkptp folder called 05 and 06, which contain subfolders 102_01 and 111_01 which then contain the downloaded images.

What I'd like to do is change the download folder and have all of the pictures stored directly inside (as apposed to being in subfolders). I read through some other threads and the multicam source code trying to make sense of it all but I'm struggling. If I need to I can make a ruby program that extracts all the images from the subfolders but I'd prefer to have it done in chdkptp directly and also keep the image files separate from the chdkptp files.

Unfortunately I'm very inexperienced with lua and I'm completely self taught so I have a hard time deciphering other peoples code. I'd like to make a script that switches the cameras to record and syncs them with a command, then waits for me to cut usb power to take the picture as I've heard that provides a better sync than using software, then allows me to download the images off the cameras into a folder and deletes them from the cameras with another command.

I'm sorry for asking this as I'm sure you've heard this asked countless times before, but you guys were such a big help before that I'd really appreciate any feedback you're willing to provide.

Thanks so much!


*

Offline reyalp

  • ******
  • 14004
Re: CHDKPTP File Downloading
« Reply #1 on: 06 / November / 2017, 21:52:57 »
What I'd like to do is change the download folder and have all of the pictures stored directly inside (as apposed to being in subfolders).
In mc:download_images() the download path + filename is specified in the dst option, using substitutions which are mostly described in the help for the imdl command
Code: [Select]
${serial,strfmt}  camera serial number, or empty if not available, default format %s
${pid,strfmt}     camera platform ID, default format %x
${ldate,datefmt}  PC clock date, os.date format, default %Y%m%d_%H%M%S
${lts,strfmt}     PC clock date as unix timestamp + microseconds, default format %f
${lms,strfmt}     PC clock milliseconds part, default format %03d
${mdate,datefmt}  Camera file modified date, converted to PC time, os.date format, default %Y%m%d_%H%M%S
${mts,strfmt}     Camera file modified date, as unix timestamp converted to PC time, default format %d
${name}           Image full name, like IMG_1234.JPG
${basename}       Image name without extension, like IMG_1234
${ext}            Image extension, like .JPG
${subdir}         Image DCIM subdirectory, like 100CANON or 100___01 or 100_0101
${imgnum}         Image number like 1234
${imgpfx}         Image prefix like IMG
${dirnum}         Image directory number like 101
${dirmonth}       Image DCIM subdirectory month, like 01, date folder naming cameras only
${dirday}         Image DCIM subdirectory day, like 01, date folder naming cameras only
${dlseq}          Sequential number incremented per file downloaded
${shotseq}        Sequential number incremented when imgnum changes.
Note the last two (dlseq and shotseq) are available in the current svn, but not yet in the posted binary files. You can use the Lua files from svn with the most recently released binary.

Multicam adds another, ${id} which is the multicam camera id.

The default dst is ${id}/${subdir}/${name}, meaning a directory based on camera ID, and then the DCIM subdirectory (like 111_01) and image name from the (like IMG_0124.JPG)

You can download everything into a single directory if you want, but you have to ensure the names are unique. For example
Code: [Select]
!mc:download_images({dst='${id}_${name}'})
will download files numbered by camera ID followed by the Canon image name.

You can add pretend=true to display the names that would be used without downloading them.


Quote
I'd like to make a script that switches the cameras to record and syncs them with a command, then waits for me to cut usb power to take the picture as I've heard that provides a better sync than using software, then allows me to download the images off the cameras into a folder and deletes them from the cameras with another command.
In the current svn version of multicam.lua, you should be able to use mc:shoot({usb_pwr_sync=true}) to trigger with USB remote. In this case, you don't need to use multicam sync, but you must trigger the shot within 10 seconds of issuing the command.
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #2 on: 09 / November / 2017, 16:48:05 »
Thanks so much for your help. I can now change the download folder and delete the images off the cameras afterwards, but is there some way I can delete the DCIM sub directory as well?

Re: CHDKPTP File Downloading
« Reply #3 on: 09 / November / 2017, 17:39:31 »
Another quick question; how do I automate commands in the chdkptp command line? Like if I were to make a new script that automatically executes
Code: [Select]
!mc=require('multicam')
!mc:connect()
and so on, how do I start?


*

Offline reyalp

  • ******
  • 14004
Re: CHDKPTP File Downloading
« Reply #4 on: 10 / November / 2017, 02:20:50 »
I can now change the download folder and delete the images off the cameras afterwards, but is there some way I can delete the DCIM sub directory as well?
There isn't currently a simple way to do this with multicam.

Do you want to delete the entire DCIM directory, or just the image directories? And is there are specific problem that is fixed by deleting?

You can use os.remove() with the call command e.g.
!mc:cmdwait([[call os.remove('A/DCIM/101___11')]])
but you would need to figure out the names of the directories to delete and make sure they are empty. I'll look into adding code to make this easier, it seems like it would be useful to have.

Another quick question; how do I automate commands in the chdkptp command line? Like if I were to make a new script that automatically executes
Code: [Select]
!mc=require('multicam')
!mc:connect()
and so on, how do I start?
One way to do this is to put the commands in a lua file, and then run it with dofile. e.g. create myfile.lua containing
Code: [Select]
mc=require('multicam')
mc:connect()
and then in chdkptp, use
Code: [Select]
!dofile('myfile.lua')
Note the lines in myfile.lua do not start with '!', because the ! is a chdkptp command to run lua code, not part of the lua code itself.

If you want to always run stuff at startup, you can put it in the startup file, described in https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk/USAGE.TXT#ln52
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #5 on: 15 / November / 2017, 22:00:16 »
Sorry for these late replies. Would there be some way to make a lua script for chdkptp that I could run, then call functions from the console?

So for example I could type camCount() and have it run only
Code: [Select]
!mc = require('multicam')
!mc:connect()

Then display the length of cams?

Then I could type camShoot() to run
Code: [Select]
!mc:start()
and so on...

edit: I just tried using !dofile and it threw the error "No such file or directory". Should it be somewhere other than the chdkptp lua folder?
« Last Edit: 15 / November / 2017, 22:07:05 by jdstech »

*

Offline reyalp

  • ******
  • 14004
Re: CHDKPTP File Downloading
« Reply #6 on: 15 / November / 2017, 23:46:17 »
Sorry for these late replies. Would there be some way to make a lua script for chdkptp that I could run, then call functions from the console?
Yes, and functions you define in the file will be available from from the ! command in chdkptp, unless you make them local

So in your example you could do
Code: [Select]
function camCount()
 mc = require('multicam')
 mc:connect()
 printf('%d\n',#mc.cams)
end
Note that you only have to do the require('multicam') once, so you could just put it at the top of your lua file, outside of any function.

Quote
edit: I just tried using !dofile and it threw the error "No such file or directory". Should it be somewhere other than the chdkptp lua folder?
dofile is relative to whatever the current directory of chdkptp is, not the the lua search path.

I suggested dofile because it's the simplest "just run the code in this file option", you can also use require, which does use the lua search path but has slightly more complicated behavior. See http://www.lua.org/manual/5.2/manual.html#6.3
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #7 on: 16 / November / 2017, 00:40:07 »
I actually just came up with a workaround. I added a new function to multicam.lua called stage that i can pass an integer into to activate different "stages". So if I type !return mc:stage(1) it runs the code
Code: [Select]
self:connect()
quay = #self.cams .. " camera detected"
return quay
and so on. mc = require('multicam') is now run at startup as well thanks to your suggestion.

Now I've gotten cocky and I'm thinking about "re-purposing" some of the gui elements to run this code for me. Would there happen to be an easy way to do that?


*

Offline reyalp

  • ******
  • 14004
Re: CHDKPTP File Downloading
« Reply #8 on: 16 / November / 2017, 01:40:05 »
Now I've gotten cocky and I'm thinking about "re-purposing" some of the gui elements to run this code for me. Would there happen to be an easy way to do that?
Assuming you are already using the chdkptp GUI, yes, look at gui.lua and add an iup.button or something. Look for
Code: [Select]
title='rec',
and do something similar with your code in the action function.

I would caution that I do most of my development in the console / command prompt cli (starting with chdkptp -i) and it is possible the GUI and multicam won't play nice together. To be clear, I don't know of any specific problem, I just haven't tested it much.
Don't forget what the H stands for.

Re: CHDKPTP File Downloading
« Reply #9 on: 27 / November / 2017, 15:35:21 »
So I just started working on implementing the power sync and I'm having some trouble. When I plug my camera into the switch and the switch into my computer it won't connect to chdk_ptp. Does this mean my switch isn't wired properly or do I have to run a command first?

If it is my switch that's the problem are there any switches I could buy that you recommend? Or if I were to make my own (a buddy made the one I'm using) is there anything I should know beforehand?

Edit: One other thing: in the action function of a button what should I put to run a command in the cli console?

Edit 2: Nevermind I just had to put the command directly into the action function, but it no longer prints what it's supposed to in the console. Before I would type !return mc:stage(1) and it would print "__ Cameras Detected" by returning that string at the end of the function. Any advice?
« Last Edit: 27 / November / 2017, 16:13:27 by jdstech »

 

Related Topics