Modifying the 2hrs video limit in the code - General Discussion and Assistance - CHDK Forum  

Modifying the 2hrs video limit in the code

  • 9 Replies
  • 365 Views
*

Offline obi

  • *
  • 13
Modifying the 2hrs video limit in the code
« on: 19 / November / 2021, 09:01:04 »
Advertisements
Hi all,

I am trying to use the SX230HS camera with CHDK to shoot a video of the longest possible length. As the quality does not matter, I am recording at 320p and using 1 as video quality in CHDK video settings. Of course I am using the script as described at https://chdk.fandom.com/wiki/Continuous_Video_Scripts

I observed that the video recording stops after 2 hours even though the video file size is only about 1.5 GB. The script kicks in and restarts the recording but I would like to have it running until the 4 GB filesystem limit.

I  was looking into the sources and found something that could be changed but was not sure how.

In the chdk/platform/sx230hs/sub/101a/code_gen.txt we have lines with 7200:

...
PATCHVAL value=0x28800000 comment="2hrs 120fps"
FW 6
PATCHVAL value=7200 comment="2hrs"
FW 26
PATCHVAL value=7200 comment="2hrs"
FW 5
REM
...

which appear to change the file movie_rec.c:

...
"loc_FF305794:\n"
"    LDR     R7, =0x57600000 \n"  // --> Patched. Old value = 0x3A980. 2hrs 240fps
"    STR     R0, [R6, #0x12C] \n"
"    MOV     R0, #0xF0 \n"

"loc_FF3057A0:\n"
"    STR     R0, [R6, #0xD8] \n"
"    B       loc_FF3057C4 \n"

"loc_FF3057A8:\n"
"    STR     R0, [R6, #0x12C] \n"
"    LDR     R7, =0x28800000 \n"  // --> Patched. Old value = 0x1D4C0. 2hrs 120fps
"    MOV     R0, #0x78 \n"
"    B       loc_FF3057A0 \n"
...

As I am new to the sources and CHDK, I need your help to change this limit. I would appreciate if someone can guide me.

Looking forward!

*

Online reyalp

  • ******
  • 13454
Re: Modifying the 2hrs video limit in the code
« Reply #1 on: 19 / November / 2021, 13:20:54 »
As I am new to the sources and CHDK, I need your help to change this limit. I would appreciate if someone can guide me.
Do you mean how to build with those values changed? If so, instructions for getting a working build environment can be found at https://chdk.fandom.com/wiki/For_Developers
If you're on windows, https://chdk.setepontos.com/index.php?topic=12752.0 is likely the most convenient way to get one

To regenerate movie_rec.c from code_gen.txt, you need to have the firmware dump for the camera you want to build in PRIMARY.BIN, and then make run-code-gen. However, you can also just edit movie_rec.c directly and build with regular make command, just be aware the changes will be lost if you run code gen again.

As to whether increasing these values will get you you past the 2 hour limit, you might find discussion from when the override was originally implemented in the porting thread (https://chdk.setepontos.com/index.php?topic=6397.0)  but the easiest way is probably just to try it.

One thing I would caution is setting the limit >= 2^31 (0x80000000) could break things if there's signed comparisons involved, so you may not want to just blindly double the 240 and 120 values. But one might guess that the low frame rate values are independent, and just replace the 7200 with 14400 or whatever.
Don't forget what the H stands for.

*

Offline Caefix

  • *****
  • 652
  • Sorry, busy deleting test shots...
Re: Modifying the 2hrs video limit in the code
« Reply #2 on: 20 / November / 2021, 12:44:55 »
Just wondering, are decimals mixed with hexadecibels?  :blink:
Maybe these lines are mentioned for slow motion only?
Code: [Select]
"    LDR     R7, =0x57600000 \n"  // --> Patched. Old value = 0x3A980. 2hrs 240fps
"    LDR     R7, =0x28800000 \n"  // --> Patched. Old value = 0x1D4C0. 2hrs 120fps
2*288=576
0x1D4C0=120000
print(string.format("%x",28800000/7200))=0xfa0=4000

Nearly empty 32GB card remaining movietime:
Slowmo framerate 120:=103min ; 240:=206min
StdVid 320*240:=946min

Edit: 946min/29GB=~33min/GB, that cam expects at average conditions.
So 2 hours recording is close to 4GB...  :-[
« Last Edit: 20 / November / 2021, 15:29:33 by Caefix »
All lifetime is a loan from eternity.

*

Offline obi

  • *
  • 13
Re: Modifying the 2hrs video limit in the code
« Reply #3 on: 20 / November / 2021, 14:30:04 »
Hi guys,

Thanks a bundle for the quick responses.

@reyalp Build part is clear, I can build. I was actually not sure what exactly I have to change and where. I would like to change the movie_rec.c directly for now and re-build. I was looking for references to 7200 (2 hrs) or in hex 0x1C20. I found out using grep -iR 1C20 sub/101a/movie_rec.c:

LDR     R1, =0x1C20 \n"  // --> Patched. Old value = 0xE0F. 2hrs
LDR     R1, =0x1C20 \n"  // --> Patched. Old value = 0x707. 2hrs

I was thinking to change the above 2 references to 0x3840 (14400) and test (though currently trying to find the FI2 offsets from the firmware that I was finally able to dump).

Do you see any other place where I will have to change?

Many thanks for your help!


*

Offline Caefix

  • *****
  • 652
  • Sorry, busy deleting test shots...
Re: Modifying the 2hrs video limit in the code
« Reply #4 on: 20 / November / 2021, 14:43:01 »
FI2?  :-[ You seem to prefere "FW-Update".
You could make card bootable with chdk-menu -> misc -> SD- card -> ...

Edit3: Btw. To run own builds where diskboot.bin is changed You NEED to boot else You compare with released PS.FI2.  ???

Edit: Might be interesting, too...
https://chdk.setepontos.com/index.php?topic=5295.msg125822#msg125822

Edit2:  ;) Could a recording_frame_counter() be involved?
« Last Edit: 21 / November / 2021, 14:58:15 by Caefix »
All lifetime is a loan from eternity.

*

Online reyalp

  • ******
  • 13454
Re: Modifying the 2hrs video limit in the code
« Reply #5 on: 20 / November / 2021, 14:49:52 »
@reyalp Build part is clear, I can build. I was actually not sure what exactly I have to change and where. I would like to change the movie_rec.c directly for now and re-build. I was looking for references to 7200 (2 hrs) or in hex 0x1C20. I found out using grep -iR 1C20 sub/101a/movie_rec.c:

LDR     R1, =0x1C20 \n"  // --> Patched. Old value = 0xE0F. 2hrs
LDR     R1, =0x1C20 \n"  // --> Patched. Old value = 0x707. 2hrs

I was thinking to change the above 2 references to 0x3840 (14400) and test
I'm not familiar with that code, but the 4 related values mentioned in the movie_rec.c section of code_gen.txt seem like the only obvious things to change, and if the comments are to be believed, those two are the only ones that should matter for normal frame rates. So your suggestion seems like a reasonable first step.

As an aside, comments in the CHDK source should not be blindly trusted. Reverse engineering often involves incomplete understanding and things get copy / pasted a lot.

Quote
(though currently trying to find the FI2 offsets from the firmware that I was finally able to dump).
Note you only need the FI2 keys if you want load manually with "firm update", you don't need them if you use autoboot. You can get the keys from *any* dump with the same FI2 encoding, so you can use  https://chdk.fandom.com/wiki/For_Developers/fi2offsets and a publicly posted dump from a camera listed there (also FWIW, the sx230 100a offsets will be very close to your firmware)
Don't forget what the H stands for.

*

Offline obi

  • *
  • 13
Re: Modifying the 2hrs video limit in the code
« Reply #6 on: 20 / November / 2021, 15:12:57 »
Thanks a lot both.

I was actually thinking that I have to make the card bootable again for my own CHDK build as I read somewhere that this is not the normal boot flag. Anyhow, it works now and I can boot using my build.

I have changed the two values and started my test. Will post the results.

Cheers!

*

Offline obi

  • *
  • 13
Re: Modifying the 2hrs video limit in the code
« Reply #7 on: 23 / November / 2021, 14:51:04 »
Hi guys,

It works! I can record up to 4 hours of really bad quality videos now. I have also tried "make run-code-gen" and the result is the same.

Thanks a lot once again. I will continue with my adventures with CHDK and hopefully be able to contribute to it at some point.

Cheers!



*

Online reyalp

  • ******
  • 13454
Re: Modifying the 2hrs video limit in the code
« Reply #8 on: 23 / November / 2021, 22:01:20 »
It works! I can record up to 4 hours of really bad quality videos now. I have also tried "make run-code-gen" and the result is the same.
Thanks for reporting. How large did the 4 hour file end up being? I guess since your previous test was 1.5 GB, it's probably over 2?
Don't forget what the H stands for.

*

Offline obi

  • *
  • 13
Re: Modifying the 2hrs video limit in the code
« Reply #9 on: 24 / November / 2021, 13:17:50 »
It works! I can record up to 4 hours of really bad quality videos now. I have also tried "make run-code-gen" and the result is the same.
Thanks for reporting. How large did the 4 hour file end up being? I guess since your previous test was 1.5 GB, it's probably over 2?
The file size is 3.0 GB for exactly 4 hours of recording at 240p.

 

Related Topics