Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new command line options to raspiraw #1

Closed
wants to merge 58 commits into from

Conversation

@Hermann-SW
Copy link
Contributor

Hermann-SW commented Dec 13, 2017

The new command line options mainly allow for high framerate video capturing into ramdisk (because SD card is too slow), up to 665fps for now.

Two options are useful for all existing modes without high framerate capturing:
--fps : allows to change framerate for each of the existing modes 1-7
--tstamps : allows to write frame capture timestamps into file for frame skip and frame delta analysis

Copy link
Owner

6by9 left a comment

A good start, but some ugly bits / things to consider.

README.md Outdated

Looking up register difference between mode4 (1296x960) and mode5 (1296x720) it can be seen that y_addr_end register (3806+3807) difference (0x07A3 versus 0x06B3) is 0xF0=240. This is the reduction in vertical resulution between both modes. For being based on mode7 the higher value is 0x07A3=1955. Keeping 64 lines from 480 means reduction by 480-64=0x01A0 from 0x07A3, which is 0x0603.

For this to work 78 is needed in register 3802 according diff between mode4 and mode5. 3802 top 4 bits are debug mode (7), while lower 4 bits are bits [11:8] of y_addr_start. Register 3803 value for bits [7:0] of y_addr_start is 0x00. Not sure what 0x0800=2048 means since that is above vertical sensor row size. But that settings makes it work.

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

You're right that modes 4&5 appear to have an error.
raspivid -w 1280 -h 720 -md 4 and raspivid -w 1280 -h 720 -md 5 should give the same FOV (with mode 5 having a slightly higher max frame rate), but they don't.
I'm looking at fixing that in the firmware now, but at first glance it appears that 0x3802 should be 0x00, and 0x3803 should be 0xF0 (240).

raspiraw.c Outdated
if (cfg.hinc >= 0)
{
// TODO: handle modes different to ov5647 as well
set_reg(sensor_mode, 0x3814, cfg.hinc);

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

0x3814 needs to come from the struct sensor_def, same as exposure_reg, vts_reg, and gain_reg,

raspiraw.c Outdated
if (cfg.vinc >= 0)
{
// TODO: handle modes different to ov5647 as well
set_reg(sensor_mode, 0x3815, cfg.vinc);

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

0x3815 needs to come from the struct sensor_def, same as exposure_reg, vts_reg, and gain_reg,

raspiraw.c Outdated

if (cfg.fps > 0)
{
// TODO: handle modes different to ov5647 as well

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

On almost all sensors vts is expressed in line periods, which you already have as sensor_mode->line_time_ns.

frame_period_nsecs = 1000000000 / cfg.fps;
n = frame_period_nsecs / sensor_mode->line_time_ns;
//write to register sensor->vts_reg

should get you to the same place in a sensor independent manner.
(I haven't checked for overflows in those calcs. You may need to use 64 bit values)

raspiraw.c Outdated

if (cfg.line > 0)
{
sensor_mode->line_time_ns = cfg.line;

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

Do you really need to ever override this? You aren't altering the line length, and I think if you are then you're better off defining a new mode.

raspiraw.c Outdated
return sensor_mode->regs[reg_index(sensor_mode, r)].data;
}

void set_reg(struct mode_def *sensor_mode, int r, int b)

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

Duplicate of modReg(mode, r, 0, 7, b, EQUAL).

raspiraw.c Outdated
sensor_mode->line_time_ns = cfg.line;
}


This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

The update_regs call at line 949 has the potential to undo anything up to this point.
Probably better to alter update_regs to take in the cfg struct (as a const) and then apply all these settings there as one central point.

@@ -946,6 +1186,22 @@ int main(int argc, const char** argv) {
brcm_header->mode.bayer_format = VC_IMAGE_BAYER_RAW16;
break;
}
if (cfg.write_header0)

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

Take in a new filename again rather than squeezing it in as file 0. The user can then choose to name it as file 0, or use something more to their liking.

cfg->ptso->idx = count;
cfg->ptso->pts = buffer->pts;
cfg->ptso->nxt = malloc(sizeof(struct pts_node));
cfg->ptso = cfg->ptso->nxt;

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

No checking the malloc succeeded -> seg fault.

Simplest solution is change line 429 to
if (cfg->write_timestamps && cfg->ptso)
or even
if (cfg->ptso)
as cfg->ptso will never get set if write_timestamps is 0.

(Lots of little mallocs like this isn't nice, but such is life. The alternative is to allocate bigger arrays to take eg 1024 timestamps, and chain those together.)

raspiraw.c Outdated
{
sensor_mode->height = cfg.height;
}

This comment has been minimized.

Copy link
@6by9

6by9 Dec 13, 2017

Owner

Thinking aloud more than anything.
To alter the crop you're currently forcing the user to specify register values and then width/height - lots of potential for errors, and I have seen it result in memory corruption (I wish I knew exactly why, as it shouldn't be possible).

Are we better off with left/right/top/bottom crop parameters that then compute the registers and width / height? I'm happy enough with a function pointer in the sensor_def to a function that works out the values rather trying to write generic code with lookup tables of registers.
hinc and vinc are the awkward ones, but again messing with those really ought to be done as a new mode.

@Hermann-SW
Copy link
Contributor Author

Hermann-SW commented Dec 13, 2017

@Hermann-SW
Copy link
Contributor Author

Hermann-SW commented Dec 14, 2017

@6by9
Copy link
Owner

6by9 commented Dec 14, 2017

You're calculating VTS to be used based on the frame rate.

The vts values in the mode_def struct is the minimum that I believe the sensor will run with, and therefore the absolute maximum framerate. They are NOT the value that is expected to be set in the register set.

Taking as an example mode7, 21165 * 484 = 10243860ns, or 10.24ms. 1000000000/(21165 * 484) = absolute max of 97.6 fps. As you'd observed, mode7 can be convinced to run up to 96fps, although 95fps in reality.
The default programmed value is 0x312, or 786. 786*21165 = 16635690ns, or 60.111fps as you had observed.

Or mode0 (5MPix), 32503 * 1968 = 654365904ns, or 65.43ms. 1000000000/(32503 * 1968) = 15.633fps, when max permitted is 15fps.

vts_reg = 1000000000 / (fps * sensor_mode->line_length should work out.

@Hermann-SW
Copy link
Contributor Author

Hermann-SW commented Dec 18, 2017

Hermann-SW added 10 commits Dec 18, 2017
Add --top, replace  -r "..."  by just --height ... --top ...
Fix issue with 416 limit
Add 640_480 and 640x480_s modes
Add two new 640x240_B* modes
- 2592_1944_s captures with 30fps (fps doubled, from mode5)
- 1296x730_s  captures with 98fps (fps doubled, from mode2)
… for 190fps.

raw2ogg2anim tool got new "dd" option for dealing with that.
@6by9 6by9 mentioned this pull request Jan 13, 2018
@6by9
Copy link
Owner

6by9 commented Jan 29, 2018

Cleaned up and merged manually.

Patches really need to be self-contained and complete, unless it really is a development "hack it together" branch (in which case it shouldn't be the source of a PR).

  • A master branch doesn't want the "something wrong" / "revert something wrong" type commits.
  • Every commit should build (git rebase -i and/or git commit --amend to fix them, with git push -f if you've already pushed the incorrect changes)
  • PRs also ought to be rebased rather than having the parent branches merged. Git does manage a lot of that, but can become ugly all too easily.
  • Excess white space (trailing spaces/tabs on blank lines) should be avoided. How rigidly enforced that is depends on the project, but generally reflects a lack of attention to detail. git show even shows it up in red, so it tends to be fairly obvious if you look at your patches.
@6by9 6by9 closed this Jan 29, 2018
@6by9
Copy link
Owner

6by9 commented Jan 29, 2018

And I must say thanks for all your efforts here too :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.