FPS control - General Discussion and Assistance - CHDK Forum supplierdeeply

FPS control

  • 36 Replies
  • 8644 Views
*

Offline funnel

  • ****
  • 349
FPS control
« on: 05 / April / 2012, 09:07:57 »
Advertisements
I've successfully managed to override the fps on my sx220 100a.

Most of the information I needed was found here:

http://magiclantern.wikia.com/wiki/VideoTimer
http://groups.google.com/group/ml-devel
http://magiclantern.wikia.com/wiki/Register_Map
their source fps_engio.c

and what srsa_4c posted here
http://chdk.wikia.com/wiki/User:Srsa_4c/Sensor_%26_LiveView_setup


Limits:
-we can only decrease FPS
-we must have a way disable the audio in video mode or go into a movie mode where audio is disabled (such as slowmotion or miniature mode on sx220)


The fps can be overridden by modifying the head timer values in registers 0xC0F0600C, 0xC0F06014 and writing 1 to 0xC0F06000 to apply changes.

The math is simple:

For example the default values for regA and regB for 30 fps:
regA=0x473
regB=0x6db+1
fps=30000
frequency=regA*regB*fps==~60,000,000,000 (0x3938700*1000)
fps=frequency/regA/regB

we can find the default values struct by looking at where the ram address points in FldSpec.c (0xBBDC).

for 30fps looks like this:

Code: [Select]
ff446e00: 000298f1
ff446e04: 03938700 frequency
ff446e08: 04740474
ff446e0c: 04740474 regA
ff446e10: 00000474
ff446e14: 000006dc regB
ff446e18: 000006dc
...
ff446e24: 00090008
ff446e28: 00000000
ff446e2c: 00000003
...
ff446e80: 002d0000
ff446e84: 00000000
ff446e88: 000a06af
...
ff446ecc: 00000001

If we want 10fps we can calculate a new value for example: regA=60,000,000,000/10000/0x6dc=0xD58

In my tests I could go as low as 0.45fps, maybe lower is still possible.

To write to the registers we can use a function found in EngDrvOut, looks like this:

Code: [Select]
FF025808                 MOV     R2, R0,LSL#14
FF02580C                 MOV     R2, R2,LSR#14
FF025810                 ORR     R2, R2, #0x400000
FF025814                 STR     R1, [R2]
FF025818                 STR     R1, [R0]
FF02581C                BX      LR


Or just rewrite it and simply SHIFT and OR the values and poke the addresses.
All this function does is converts the digic register address to a ram address 0xC0F06014->0X00406014 and stores the new value in both locations. To monitor what’s going on  we can simply look at 0X004060C and 0X00406014 in the memory browser.


Disabling audio

The slow motion video mode on sx220 is limited to 640x480 so I needed to find a way to disable the audio to be able to use higher resolutions with fps overrides. This was the hardest part but I got lucky.

To do it we have to:
-modify a ram location(*(0xC2E3C+0x8)=0) in the right place in movie_rec.c task to prevent the audio being written.
-start recording and call a function that effectively disables the AudioIC and prevents a crash after the recording stops.

Code: [Select]
"loc_FF1879E8:\n"
                "LDR    R1, =0x777\n"
                "LDR    R0, =0xFF186114\n"
                "BL sub_FF00EC88\n"
"loc_FF1879F4:\n"
  );

if( (int)conf.disable_audio == 1)
{
asm volatile("BL disable_audio\n");
}

asm volatile(
"LDR    R2, =0x8552\n"
                "LDR    R0, [R6, #0xB8]\n"
                "MOV    R3, #2\n"
                "MOV    R1, #0xAA\n"
                "BL sub_FF08AD7C\n"

Code: [Select]
void __attribute__((naked,noinline)) disable_audio(  ) {

asm volatile (
"STMFD  SP!, {R0-R1,LR}\n"
"LDR R0, =0xC2E3C\n"
"MOV R1, #0\n"
"STR R1, [R0,#8]\n"
"LDMFD  SP!, {R0-R1,PC}\n"
);
}


Code: [Select]
"loc_FF1883F4:\n"
  );

extern short movie_status;
if( (int)conf.disable_audio == 1 && movie_status==4 && *(int*)0x85B8==1)  //if recording_started && is_first_frame
{
asm volatile(
"BL sub_FF05BA94\n" //function that disables the AudioIC.
);
}

asm volatile (

"LDR     R1, [R4,#0xF0]\n"
                 "BLX     R1\n"


I found the function by backtracing 0xC0920000+0x118(audio on/off flag)  to the movie record task.

I also wrote a lua script to play with it, I guess it could work on other cameras with a video mode where audio is disabled.

Use at your own risk.

Re: FPS control
« Reply #1 on: 05 / April / 2012, 16:30:51 »
Good work as usual.

So, if I monitor the field synch pulse on the A/V output of two S95's, there will be a random phase difference between them.

It is assumed (but not proven) that the instant of capturing each frame is related to the timing of the field synch pulse.

If, with a single press of a button, the fps of one of the cameras is made slower by a tiny amount I wonder if the two synch pulses will drift into phase ?

At that point, another press of the button could restore the original fps, hopefully maintaining synch.


*

Offline funnel

  • ****
  • 349
Re: FPS control
« Reply #2 on: 05 / April / 2012, 17:23:58 »
Yes, I think it'll work if you know how to detect when they're out of synch.

Re: FPS control
« Reply #3 on: 05 / April / 2012, 17:51:12 »
It would be the modern equivalent of something like the circuit shown here :-

http://www.ledametrix.com/syncshep/index.html

The S95 has a miniature mode so once synch was achieved it should remain the same when switching to normal HD video mode.


I will come back to this once I have time.



Re: FPS control
« Reply #4 on: 05 / April / 2012, 18:37:04 »
Great work Funnel! There seems to be a lot of cross pollination going on between the MagicLantern & CHDK team these days.

Any reason this wouldn't also work on CCD based Powershot camera's? (such as the SX150IS). Do they all use the same Digic registers?

I'd like to see a "MagicLantern for Powershot" one day, complete with full manual video control in the menu's & live HDMI out, wishful thinking perhaps...?


Re: FPS control
« Reply #5 on: 14 / October / 2012, 19:04:44 »
HI all, thanks for sharing, but I got a question. I got one sx230hs, is it possible to record videos in 24fps but using a different shutter speed, like 1/48; 1/60 or so on. with 1/48 we got a cine-style.
Another question, is it possible to get a technicolor cine-style to record a flat image and then post process on Adobe Premiere?

Cheers mate,

Re: FPS control
« Reply #6 on: 28 / October / 2012, 03:39:22 »
I would also like to see additional video controls, mainly a way to lock exposure, and probably someday, unlock 1080p 30fps which the CPU is able to handle unless canon is running the sx220 and 230 at a lower clock speed

Re: FPS control
« Reply #7 on: 28 / October / 2012, 09:59:36 »
HI all, thanks for sharing, but I got a question. I got one sx230hs, is it possible to record videos in 24fps but using a different shutter speed, like 1/48; 1/60 or so on. with 1/48 we got a cine-style.
Another question, is it possible to get a technicolor cine-style to record a flat image and then post process on Adobe Premiere?
I would also like to see additional video controls, mainly a way to lock exposure, and probably someday, unlock 1080p 30fps which the CPU is able to handle unless canon is running the sx220 and 230 at a lower clock speed
This will take a skilled developer with a lot of fee of time and a lot of luck (you can't hook what isn't there).

Right now, none of the very small group of CHDK devs seems very interested in video so unless someone new expresses interest and has the time & skills,  its not going to happen.
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline a1ex

  • *****
  • 671
  • ML dev
Re: FPS control
« Reply #8 on: 07 / April / 2013, 18:36:52 »
Here's my attempt at overriding FPS on A2200.

1) digic.lua: this one is for investigation - it will try to autodetect the memory area where DIGIC registers are mirrored (this is needed for reading the current values) and will save a log with all register values from the C0F0xxxx range. If you try it, I'd like to ask you to post the log file, it may be useful in better understanding the FPS timers.

2) fps.lua: this is a bit more user-friendly: you set the timer values, the script will try to estimate the FPS. You will have to set the main clock first (and digic.lua can help with guessing). Higher timer values = lower FPS.

Only run these scripts if you are not afraid of things going wrong. They are far from "just works" and seem to crash quite often.

Known bug: the function "restore" in fps.lua doesn't get called when the script is interrupted (according to http://chdk.wikia.com/wiki/Script_commands#restore it should, not sure what's wrong)

*

Offline lapser

  • *****
  • 1093
Re: FPS control
« Reply #9 on: 07 / April / 2013, 18:57:01 »
Known bug: the function "restore" in fps.lua doesn't get called when the script is interrupted
I usually try to exit a program in a more controlled way than interrupting it with the shutter button, which happens at a random point in the program.

Code: [Select]
function restore()
--restore code
end

repeat
  --loop code
  wait_click(50)
until is_key("menu")
restore()

EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics