BreeeZe / rpos

Raspberry Pi Onvif Server
http://breeeze.github.io/rpos
MIT License
643 stars 146 forks source link

Make resolution/frame rate controllable via ONVIF #157

Open wryun opened 1 year ago

wryun commented 1 year ago

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

RogerHardiman commented 1 year ago

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.

universe241981 commented 9 months ago

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

wryun commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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

wryun commented 8 months ago

@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 commented 8 months ago

@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 commented 8 months ago

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 commented 8 months ago

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
}