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

Make resolution/frame rate controllable via ONVIF #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wryun
Copy link

@wryun wryun commented Apr 21, 2023

  • restart server if necessary (kernel blocks access when streaming?)
  • move persistence from v4l2ctl.ts to camera.ts

The restart logic here is particularly messy/ugly; it's just what we needed. Not sure if I'm going to have time to make it a bit nicer, but thought I'd leave the PR here in case anyone's interested in what needs to be done for #63

- persist in videoencoderconfiguration
- restart server if necessary (kernel blocks access when streaming?)
- remove unsupported profile selection and allow quality 0,1 for vbr/cbr
lib/camera.ts Outdated
v4l2ctl.ApplyControls();

if (this.config.RTSPServer === 1) {
// If it's our RTSPServer, we should have sufficient access to change resolution.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think looking at how it's launched this is probably not true, but I haven't actually tested it.

@RogerHardiman
Copy link
Collaborator

Many thanks for this.
You are correct that some of the functionality here has started to break over the last few years.
Originally the code used the Raspberry Pi H264 encoder via the V4L2 interface and some things could be changed on the fly.
When the other RTSP servers (eg Gstreamer) then the options to restart the RTSP servers were not included.
So working in this area in the source code will be good.

@@ -16,7 +22,6 @@ class Camera {
{ Width: 1024, Height: 768 },
{ Width: 1280, Height: 1024 },
{ Width: 1280, Height: 720 },
{ Width: 1640, Height: 1232 },
Copy link
Author

@wryun wryun Apr 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my Camera 2.1 module this resolution was causing issues. I believe it's because the height is greater than 1080.

@@ -102,11 +109,6 @@ class Camera {
utils.cleanup(() => {
this.stopRtsp();
var stop = new Date().getTime() + 2000;
while (new Date().getTime() < stop) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is only necessary because of the driver unload below, which was commented out. I think it's a good idea not to get involved with module loading/unloading and leave this to the user if necessary.

Previously, some camera settings were persisted in v4l2ctl.json, but
others were not (either overwritten by subsequent actions or never
there in the first place).

This tries to make sure there's only one place we're storing
settings, and then makes sure to save them all. The
signal-exit package is introduced to more reliably handle
exit cleanups, which is now more important if the user
has just changed a setting (save runs on a 30 sec delay).

Also re-introduce H264 profile handling.
@universe241981
Copy link

The resolution/frame rate is not controllable with wryun repo.

@wryun
Copy link
Author

wryun commented Sep 19, 2023

We're using this code now and it seems to work for us with the v4l2rtspserver backend. If you could explain how it's not working, I might be able to help. Make sure you're on the correct branch, not the master branch.

@universe241981
Copy link

Hi wryun,
I have tested again. I am git clone it from https://github.com/wryun/rpos.git
I cannot adjust the resolution as well as frame rate via ONVIF. It jump back to 720p and 25 fps.
I am testing it on RPi3B with RaspOS Bullseye.

@universe241981
Copy link

I have tried RaspiOS Buster. Same situation. Cannot set resolution and frame rate via ONVIF

@wryun
Copy link
Author

wryun commented Oct 22, 2023

@universe241981 all I can say is it works assuming you're using v4l2rtspserver. Are you sure you checked out the right branch from that repository?

@universe241981
Copy link

universe241981 commented Oct 23, 2023

@wryun please correct me if I am wrong.

I am using bullseye.
I acquired the source code via "wget https://github.com/wryun/rpos/archive/refs/heads/allow-setting-resolution-and-fps.zip"
unzip it then begin the usual installation method.

This time, I found error message below:

/home/pi/rpos/node_modules/signal-exit/dist/cjs/index.js:162
const ev = opts?.alwaysLast ? 'afterExit' : 'exit';
^

SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/pi/rpos/lib/camera.js:7:21)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

@wryun
Copy link
Author

wryun commented Oct 23, 2023

Looks like you're using an old version of NodeJS that doesn't support ?.

(this problem is in a dependency rather than in the code itself)

Looking at the dependency, this is probably my fault; try upgrading to a later version of NodeJS (or potentially downgrading signal-exit).

@universe241981
Copy link

universe241981 commented Oct 25, 2023

You are right. The installation instruction in the README is NodeJS version 12. While this branch can use version up to 16 only. Version 18 onward will have error below at "npx gulp":

Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
    at readWasm (/home/pi/rpos/node_modules/gulp-typescript/node_modules/source-map/lib/read-wasm.js:8:13)
    at wasm (/home/pi/rpos/node_modules/gulp-typescript/node_modules/source-map/lib/wasm.js:25:16)
    at /home/pi/rpos/node_modules/gulp-typescript/node_modules/source-map/lib/source-map-consumer.js:264:14
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

and leaded to error below if execute "node rpos.js":

node:internal/modules/cjs/loader:1080
  throw err;
  ^

Error: Cannot find module '/home/pi/rpos/rpos.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.18.2

Anyway, the resolution/fps is controllable via ONVIF with this branch and with NodeJS 16.

By the way, I also implemented the timestamp overlay function from "www.linux-projects.org"...with some hardcode on the ".json" file. But unfortunately I cannot utilize the rpos.service for it to start up at boot. As work around, I put the "node rpos.js" command in the .bashrc file and it work with some message:

Read IP address IP from eth0
Manufacturer : Raspberry Pi
Model : Zero 2 W
HardwareId :
SerialNumber : 00000000b5c67c05
FirmwareVersion : 2.1.0
Could not retrieve Controlvalue 'horizontal_flip'
Could not retrieve Controlvalue 'vertical_flip'
Could not retrieve Controlvalue 'power_line_frequency'
Could not retrieve Controlvalue 'color_effects'
Could not retrieve Controlvalue 'color_effects_cbcr'
Could not retrieve Controlvalue 'video_bitrate_mode'
Could not retrieve Controlvalue 'video_bitrate'
Could not retrieve Controlvalue 'repeat_sequence_header'
Could not retrieve Controlvalue 'h264_i_frame_period'
Could not retrieve Controlvalue 'h264_level'
Could not retrieve Controlvalue 'h264_profile'
Could not retrieve Controlvalue 'auto_exposure'
Could not retrieve Controlvalue 'exposure_time_absolute'
Could not retrieve Controlvalue 'exposure_dynamic_framerate'
Could not retrieve Controlvalue 'auto_exposure_bias'
Could not retrieve Controlvalue 'white_balance_auto_preset'
Could not retrieve Controlvalue 'exposure_metering_mode'
Could not retrieve Controlvalue 'scene_mode'
Could not retrieve Controlvalue 'compression_quality'
unknown control 'compression_quality'
Starting camera settings webserver on http://IP:8081/
Binding DeviceService to http://IP:8081/onvif/device_service
Binding MediaService to http://IP:8081/onvif/media_service
Binding PTZService to http://IP:8081/onvif/ptz_service
Binding ImagingService to http://IP:8081/onvif/imaging_service
discovery_service started
Stopping rtsp server
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::8081
    at Server.setupListenHandle [as _listen2] (node:net:1463:16)
    at listenInCluster (node:net:1511:12)
    at Server.listen (node:net:1599:7)
    at Object.<anonymous> (/home/pi/rpos/rpos.js:85:12)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1490:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 8081
}

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

Successfully merging this pull request may close these issues.

3 participants