How do PowerShots control photo and video resolutions? - General Discussion and Assistance - CHDK Forum

How do PowerShots control photo and video resolutions?

  • 14 Replies
  • 3322 Views
How do PowerShots control photo and video resolutions?
« on: 02 / January / 2024, 18:05:17 »
Advertisements
So, I don't understand, we can control ISO, Aperture, Shutter Speed, etc. through CHDK. But why not control video/photo resolution? How exactly does the PowerShot know that it's supposed to film at let's say 640x480? There's got to be something that tells the sensor to capture in that predefined resolution. Right? Technically, it could be possible to monitor the memory changes live, while switching video resolutions, to see what those settings trigger, and find out what memory address changes and then inject custom values to make custom resolutions? Or is it something else that doesn't allow this to be done? I'm confused. It doesn't seem to be impossible. Reyalp? I think this one's for you, since you know a lot about the YUV frame buffers and stuff. Maybe you could explain why CHDK can't do this yet? Since technically this shouldn't be any harder than finding how to control the ISO, Aperture, and Shutter Speed. Right? :)

*

Offline reyalp

  • ******
  • 14126
Re: How do PowerShots control photo and video resolutions?
« Reply #1 on: 02 / January / 2024, 21:00:41 »
So, I don't understand, we can control ISO, Aperture, Shutter Speed, etc. through CHDK. But why not control video/photo resolution? How exactly does the PowerShot know that it's supposed to film at let's say 640x480? There's got to be something that tells the sensor to capture in that predefined resolution. Right?
Well, there's got be something, but I'd expect it's not one thing. There will be parameters for the readout hardware, parameters for the display, parameters for the hardware that does jpeg and video encoding, and for all the software that ties them together. There's no particular reason to think there's one place that sets "width=640, height=480" and that you could just replace those with arbitrary values. It's likely that some of the subsystems involved only expect certain, specific values.

Even if those limits aren't hardware limits (which they could well be in some cases) the firmware code tends to have a variables where say, display mode 1 is 720x240, and 2 is 720x480. Various parts of the code then have switch statements involving the mode variable, and which set a bunch of parameters accordingly. To set a custom mode, you can't just set the mode variable, you'd have to find out everywhere it was used and find a way to override all the different values.

Worse, it's not necessarily a matter of just finding some simple variables. For example, the live view typically has 3-4 frame buffers packed together, starting at some specific address (so if buffer one is at X, buffer two is at X + 640*480*bit depth). If you made the resolution bigger, then all but the first buffer would need to move, and even worse, the space immediately after the buffers is likely used by some unrelated thing that would be broken if they grew.

Note the above description refers to the display system, because I have explored that code to some extent. This is related to and interacts with video recording, but isn't the same thing.

All that said, my limited understanding is that magic lantern managed to implement raw video at somewhat arbitrary resolutions, so perhaps examining how they did that would provide insights relevant to CHDK. I haven't looked into it myself.

Quote
Technically, it could be possible to monitor the memory changes live, while switching video resolutions, to see what those settings trigger, and find out what memory address changes and then inject custom values to make custom resolutions?
In theory, sure. In practice, a lot of things change, and identifying the significant ones could be challenging. And as described above, even knowing the changes doesn't mean you can necessarily just set arbitrary values.
Quote
Or is it something else that doesn't allow this to be done? I'm confused. It doesn't seem to be impossible. Reyalp? I think this one's for you, since you know a lot about the YUV frame buffers and stuff. Maybe you could explain why CHDK can't do this yet? Since technically this shouldn't be any harder than finding how to control the ISO, Aperture, and Shutter Speed. Right? :)
Exposure parameters are significantly simpler, and happen to be exposed through a well defined interface. There is no reason to assume the same applies to other things.
Don't forget what the H stands for.

Re: How do PowerShots control photo and video resolutions?
« Reply #2 on: 02 / January / 2024, 22:27:29 »
What about the physical options in the menu? So like I can select 480p 30fps, 360p 60fps, and so on. What if we directly wrote to that? So if let's say 1 = 480p 30fps and 2 = 360 60fps, what if you select 3? Perhaps there's a hidden mode that was in beta testing but they realized it makes the camera heat up and crash if used too long, or maybe file sizes were too big for the time, or maybe even they were planning to release it in the next camera, and just had it programmed in the firmware, but off limits. I wish there was a way to try probing this stuff in-camera, and inject into these sections, and see if some mode comes up. If that's even possible...

*

Offline reyalp

  • ******
  • 14126
Re: How do PowerShots control photo and video resolutions?
« Reply #3 on: 05 / January / 2024, 00:36:39 »
What if we directly wrote to that? So if let's say 1 = 480p 30fps and 2 = 360 60fps, what if you select 3?
If it doesn't exist, then the camera probably crashes, or possibly just ignores it.
Quote
Perhaps there's a hidden mode that was in beta testing but they realized it makes the camera heat up and crash if used too long, or maybe file sizes were too big for the time,
It's certainly possible there are undocumented modes. Some cameras have undocumented display modes, but they notably seem to not be fully functional. Some parts are there, presumably because the code is shared with other models that have additional display options, but the rest of the firmware isn't set up to use them.
Quote
or maybe even they were planning to release it in the next camera, and just had it programmed in the firmware, but off limits.
Just speaking as a programmer generally, bugs are plenty and time is short, so as with the display modes mentioned above, "some parts there but broken" tends to be a more common outcome than "fully implemented and working but disabled" in this kind of case.
Quote
I wish there was a way to try probing this stuff in-camera, and inject into these sections, and see if some mode comes up. If that's even possible...
CHDK gives the ability to experiment, you can call any function or change any value in RAM, but doing so productively generally requires reverse engineering. Neither of our opinions about what might be possible really matter, the only way to find out is to do the work.
Don't forget what the H stands for.

Re: How do PowerShots control photo and video resolutions?
« Reply #4 on: 05 / January / 2024, 02:49:46 »
So, does CHDK have a function to control the resolution mode? I'm not exactly sure how to do this. I know that CHDK can control the mode of shooting like Manual, Program, Av, Tv, Sports, SCN and more, but I haven't seen any way to select video resolution modes through the overrides.

*

Offline reyalp

  • ******
  • 14126
Re: How do PowerShots control photo and video resolutions?
« Reply #5 on: 05 / January / 2024, 14:26:53 »
So, does CHDK have a function to control the resolution mode?
Standard video settings are available through propcases. Sometimes shooting mode may also imply particular resolution and frame rate (e.g. VIDEO_STD, VIDEO_SPEED, VIDEO_IFRAME_MOVIE, vs some default setting if you start recording video in a still mode). There's been a fair bit of variation in how Canon implemented the settings over there years. The propcases are somewhat documented in the propsetN.h files in https://app.assembla.com/spaces/chdk/subversion/source/HEAD/trunk/include and https://chdk.fandom.com/wiki/PropertyCase

On elph130, the following chdkptp commands record one video at 1280x720@25, and one that claims to be 640x480@25 (because the default for 720 is 25 and I didn't change the framerate prop) but AFAIK is actually recorded @30 and just mislabeled in the metadata.
Code: [Select]
$ chdkptp -c -i
connected: Canon PowerShot ELPH 130 IS, max packet size 512
con> rec
con 1> =p=require'propcase' return get_prop(p.VIDEO_RESOLUTION), get_prop(p.VIDEO_FRAMERATE)
2:return:4
2:return:1
con 2> =click'video' sleep(2000) click'video'
con 3> =p=require'propcase' set_prop(p.VIDEO_RESOLUTION,2) return get_prop(p.VIDEO_RESOLUTION), get_prop(p.VIDEO_FRAMERATE)
4:return:2
4:return:1
con 4> =click'video' sleep(2000) click'video'
con 5> play
con 6> imdl -rm -d=${name}
A/DCIM/193___01/MVI_0670.MOV->MVI_0670.MOV
A/DCIM/193___01/MVI_0671.MOV->MVI_0671.MOV
delete A/DCIM/193___01/MVI_0670.MOV
delete A/DCIM/193___01/MVI_0671.MOV
con 9> q

$ ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv MVI_0670.MOV
stream,30

$ ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv MVI_0671.MOV
stream,41
Note the clips are shorter than 2s because it takes a significant amount of time to start recording after video is pressed.

Quote
I'm not exactly sure how to do this. I know that CHDK can control the mode of shooting like Manual, Program, Av, Tv, Sports, SCN and more, but I haven't seen any way to select video resolution modes through the overrides.
CHDK doesn't expose the video propcases through the override UI because (as far as we know) it wouldn't give anything useful beyond what the factory UI gives.
Don't forget what the H stands for.

Re: How do PowerShots control photo and video resolutions?
« Reply #6 on: 05 / January / 2024, 15:55:41 »
I tried typing in the chdkptp commands "set_prop(p.VIDEO_RESOLUTION,2)", but it said there's no command called "set_prop". This is actually an issue I always get with any of these props, and this is one of the reasons I can't really do real experimenting. I'm not sure why it doesn't work. It seems everybody talks about how it does all sorts of things, but on my end, it never works.

*

Offline reyalp

  • ******
  • 14126
Re: How do PowerShots control photo and video resolutions?
« Reply #7 on: 05 / January / 2024, 17:01:22 »
I tried typing in the chdkptp commands "set_prop(p.VIDEO_RESOLUTION,2)", but it said there's no command called "set_prop"
What is the exact command you used? Note the '=' is the chdkptp command, which means "run Lua code on the camera, wait for it to complete, and return any return values". Everything after the = is CHDK Lua, which uses the function documented on https://chdk.fandom.com/wiki/CHDK_Scripting_Cross_Reference_Page
Don't forget what the H stands for.

Re: How do PowerShots control photo and video resolutions?
« Reply #8 on: 05 / January / 2024, 18:02:28 »
I connected up the camera with USB to my laptop. Started chdkptp-r964 GUI, and hit connect. Then I entered "rec" mode using the rec button. Then in the console I typed exactly the following code.
Code: [Select]
set_prop(p.VIDEO_RESOLUTION,2)After hitting enter, CHDKPTP Pooped.  :lol

*

Offline reyalp

  • ******
  • 14126
Re: How do PowerShots control photo and video resolutions?
« Reply #9 on: 05 / January / 2024, 18:49:08 »
I connected up the camera with USB to my laptop. Started chdkptp-r964 GUI, and hit connect. Then I entered "rec" mode using the rec button. Then in the console I typed exactly the following code.
Code: [Select]
set_prop(p.VIDEO_RESOLUTION,2)
As I explained in the previous reply, the correct command would start with '='
However, you have also omitted the "p=require'propcase' ", so the p.VIDEO_RESOLUTION would also fail.
The p=require'propcase' part loads the propcase module, which allows you to access propcases by name rather than propset-specific number. See https://chdk.fandom.com/wiki/Lua/Lua_Reference#get_prop

The full command would be
Code: [Select]
=p=require'propcase' set_prop(p.VIDEO_RESOLUTION,2)
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal