moeiscool / homebridge-shinobi

A Homebridge plugin integrating Shinobi for motion detector cameras
MIT License
11 stars 2 forks source link

Having Trouble Viewing Streams on iOS #7

Closed huyqt closed 2 years ago

huyqt commented 3 years ago

Hello,

I'm having some trouble viewing streams on iOS. It looks like it attempts to direct stream but the process just times out with no video feed. [11/24/2020, 2:41:56 PM] [Shinobi] ShinobiStreamingDelegate using direct camera source: rtmp://192.168.250.14/bcs/channel0_main.bcs?channel=0&stream=0&user=XXX&password=XXX [11/24/2020, 2:54:06 PM] [Shinobi] killing: JZXytNMpRT => ffebc5-de51-4aee-b378-24ab59d3d22a => PID: 11864

Or if I try to go through the non-direct streaming route, ffmpeg dies immediately: [11/24/2020, 2:19:19 PM] [Shinobi] ShinobiStreamingDelegate using direct camera source: rtsp://XXX:XXX@192.168.250.14:554/h264Preview_01_main [11/24/2020, 2:19:47 PM] [Shinobi] ffmpeg exited with code: 1 and signal: null (error)

I've also read in your other issue that there is a hardcoded resolution that you may expect (which looks like it's 16:9 vs my 4:3 640x480).

In my case, I setup a primary recording stream at full resolution on Shinobi and added second input stream for viewing (via https://hub.shinobi.video/articles/view/w8azEAI2peYeNul). I was wondering if it was possible to point the Homebridge plugin to this secondary stream location.

Here's my camera API output for direct streams: { "mid": "F1d5zLd9Yg", "ke": "ZLukWssdUR", "name": "Cam3", "shto": "[]", "shfr": "[]", "details": "{\"max_keep_days\":\"\",\"notes\":\"\",\"dir\":\"\",\"rtmp_key\":\"\",\"auto_host_enable\":\"1\",\"auto_host\":\"rtmp://192.168.250.15/bcs/channel0_main.bcs?channel=0&stream=0&user=XXX&password=XXX\",\"rtsp_transport\":\"tcp\",\"muser\":\"\",\"mpass\":\"\",\"port_force\":\"0\",\"fatal_max\":\"0\",\"skip_ping\":null,\"is_onvif\":null,\"onvif_port\":\"\",\"primary_input\":\"0:0\",\"aduration\":\"1000000\",\"probesize\":\"1000000\",\"stream_loop\":\"0\",\"sfps\":\"15\",\"wall_clock_timestamp_ignore\":\"1\",\"accelerator\":\"0\",\"hwaccel\":\"cuvid\",\"hwaccel_vcodec\":\"\",\"hwaccel_device\":\"\",\"use_coprocessor\":null,\"stream_type\":\"hls\",\"stream_flv_type\":\"ws\",\"stream_flv_maxLatency\":\"\",\"stream_mjpeg_clients\":\"\",\"stream_vcodec\":\"copy\",\"stream_acodec\":\"copy\",\"hls_time\":\"2\",\"hls_list_size\":\"3\",\"preset_stream\":\"ultrafast\",\"stream_quality\":\"15\",\"stream_fps\":\"\",\"stream_scale_x\":\"\",\"stream_scale_y\":\"\",\"rotate_stream\":\"no\",\"signal_check\":\"10\",\"signal_check_log\":\"0\",\"svf\":\"\",\"tv_channel\":\"0\",\"tv_channel_id\":\"\",\"tv_channel_group_title\":\"\",\"stream_timestamp\":\"0\",\"stream_timestamp_font\":\"\",\"stream_timestamp_font_size\":\"\",\"stream_timestamp_color\":\"\",\"stream_timestamp_box_color\":\"\",\"stream_timestamp_x\":\"\",\"stream_timestamp_y\":\"\",\"stream_watermark\":\"0\",\"stream_watermark_location\":\"\",\"stream_watermark_position\":\"tr\",\"snap\":\"1\",\"snap_fps\":\"\",\"snap_scale_x\":\"\",\"snap_scale_y\":\"\",\"snap_vf\":\"\",\"vcodec\":\"copy\",\"crf\":\"1\",\"preset_record\":\"\",\"acodec\":\"aac\",\"record_scale_y\":\"\",\"record_scale_x\":\"\",\"cutoff\":\"15\",\"rotate_record\":\"no\",\"vf\":\"\",\"timestamp\":\"0\",\"timestamp_font\":\"\",\"timestamp_font_size\":\"10\",\"timestamp_color\":\"white\",\"timestamp_box_color\":\"0x00000000@1\",\"timestamp_x\":\"(w-tw)/2\",\"timestamp_y\":\"0\",\"watermark\":\"0\",\"watermark_location\":\"\",\"watermark_position\":\"tr\",\"record_timelapse\":\"0\",\"record_timelapse_mp4\":null,\"record_timelapse_fps\":\"1800\",\"record_timelapse_scale_x\":\"640\",\"record_timelapse_scale_y\":\"480\",\"record_timelapse_vf\":\"\",\"record_timelapse_watermark\":null,\"record_timelapse_watermark_location\":\"\",\"record_timelapse_watermark_position\":null,\"cust_input\":\"\",\"cust_stream\":\"\",\"cust_snap\":\"\",\"cust_record\":\"\",\"cust_detect\":\"\",\"cust_detect_object\":\"\",\"cust_sip_record\":\"\",\"custom_output\":\"\",\"detector\":\"1\",\"detector_http_api\":null,\"detector_send_frames\":\"1\",\"detector_fps\":\"\",\"detector_scale_x\":\"640\",\"detector_scale_y\":\"480\",\"detector_lock_timeout\":\"\",\"detector_save\":\"1\",\"detector_record_method\":\"sip\",\"detector_trigger\":\"1\",\"detector_trigger_record_fps\":\"\",\"detector_timeout\":\"10\",\"detector_send_video_length\":\"\",\"watchdog_reset\":\"0\",\"detector_delete_motionless_videos\":\"0\",\"det_multi_trig\":null,\"group_detector_multi\":\"\",\"detector_webhook\":\"1\",\"detector_webhook_url\":\"http://192.168.50.2:8080/mid={{MONITOR_ID}}&group={{GROUP_KEY}}\",\"detector_webhook_method\":null,\"detector_command_enable\":\"0\",\"detector_command\":\"\",\"detector_command_timeout\":\"\",\"snap_seconds_inward\":\"\",\"detector_mail\":\"0\",\"detector_mail_timeout\":\"\",\"detector_discordbot\":null,\"detector_discordbot_send_video\":null,\"detector_discordbot_timeout\":\"\",\"use_detector_filters\":null,\"use_detector_filters_object\":null,\"cords\":\"[]\",\"detector_filters\":\"\",\"detector_pam\":\"1\",\"detector_sensitivity\":\"\",\"detector_max_sensitivity\":\"\",\"detector_threshold\":\"1\",\"detector_color_threshold\":\"\",\"detector_frame\":\"0\",\"detector_noise_filter\":null,\"detector_noise_filter_range\":\"\",\"detector_notrigger\":\"0\",\"detector_notrigger_mail\":\"0\",\"detector_notrigger_discord\":null,\"detector_notrigger_timeout\":\"\",\"detector_notrigger_webhook\":null,\"detector_notrigger_webhook_url\":\"\",\"detector_notrigger_webhook_method\":null,\"detector_notrigger_command_timeout\":\"\",\"detector_notrigger_command_enable\":null,\"detector_notrigger_command\":\"\",\"detector_audio\":null,\"detector_audio_min_db\":\"\",\"detector_audio_max_db\":\"\",\"detector_use_detect_object\":\"0\",\"detector_send_frames_object\":null,\"detector_obj_count_in_region\":null,\"detector_obj_region\":null,\"detector_use_motion\":\"1\",\"detector_fps_object\":\"\",\"detector_scale_x_object\":\"\",\"detector_scale_y_object\":\"\",\"detector_lisence_plate\":\"0\",\"detector_lisence_plate_country\":\"us\",\"detector_buffer_vcodec\":\"copy\",\"detector_buffer_acodec\":\"aac\",\"detector_buffer_fps\":\"\",\"detector_buffer_hls_time\":\"\",\"detector_buffer_hls_list_size\":\"\",\"detector_buffer_start_number\":\"\",\"detector_buffer_live_start_index\":\"\",\"control\":\"0\",\"control_base_url\":\"\",\"control_url_method\":null,\"control_digest_auth\":null,\"control_stop\":\"0\",\"control_url_stop_timeout\":\"\",\"detector_ptz_follow\":null,\"detector_ptz_follow_target\":\"\",\"detector_obj_count\":null,\"control_url_center\":\"\",\"control_url_left\":\"\",\"control_url_left_stop\":\"\",\"control_url_right\":\"\",\"control_url_right_stop\":\"\",\"control_url_up\":\"\",\"control_url_up_stop\":\"\",\"control_url_down\":\"\",\"control_url_down_stop\":\"\",\"control_url_enable_nv\":\"\",\"control_url_disable_nv\":\"\",\"control_url_zoom_out\":\"\",\"control_url_zoom_out_stop\":\"\",\"control_url_zoom_in\":\"\",\"control_url_zoom_in_stop\":\"\",\"groups\":\"[\\\"5Kl0F\\\"]\",\"loglevel\":\"warning\",\"sqllog\":\"0\",\"detector_cascades\":\"\",\"stream_channels\":\"\",\"input_maps\":\"[{\\\"type\\\":\\\"h264\\\",\\\"fulladdress\\\":\\\"rtmp://192.168.250.15/bcs/channel0_sub.bcs?channel=0&stream=0&user=XXX&password=XXX\\\",\\\"sfps\\\":\\\"15\\\",\\\"aduration\\\":\\\"\\\",\\\"probesize\\\":\\\"\\\",\\\"stream_loop\\\":\\\"0\\\",\\\"rtsp_transport\\\":\\\"\\\",\\\"accelerator\\\":\\\"0\\\",\\\"hwaccel\\\":\\\"auto\\\",\\\"hwaccel_vcodec\\\":\\\"auto\\\",\\\"hwaccel_device\\\":\\\"\\\"}]\",\"input_map_choices\":\"{\\\"stream\\\":[{\\\"map\\\":\\\"1\\\"}],\\\"snap\\\":[],\\\"record\\\":[],\\\"record_timelapse\\\":[],\\\"detector\\\":[{\\\"map\\\":\\\"1\\\"}]}\"}", "type": "h264", "ext": "mp4", "protocol": "rtmp", "host": "192.168.250.15", "path": "/bcs/channel0_main.bcs?channel=0&stream=0&user=XXX&password=XXX", "port": 80, "fps": 1, "mode": "record", "width": 640, "height": 480, "currentlyWatching": 1, "currentCpuUsage": 0.01, "status": "Recording", "snapshot": "/Yvv7jTdhyJVLV49TzFt5wW0UjWc0wx/jpeg/ZLukWssdUR/F1d5zLd9Yg/s.jpg", "streams": [ "/Yvv7jTdhyJVLV49TzFt5wW0UjWc0wx/hls/ZLukWssdUR/F1d5zLd9Yg/s.m3u8" ], "streamsSortedByType": { "hls": [ "/Yvv7jTdhyJVLV49TzFt5wW0UjWc0wx/hls/ZLukWssdUR/F1d5zLd9Yg/s.m3u8" ] } }

You'll see that there's a stream in there for channel0_main.bcs/channel0_sub.bcs for streaming via RTMP. Though it looks like the streams[0] is correctly pointing to my HLS stream that's 640x480.

From what I saw in the code, in the failing direct stream case, it's pulling the auto_host URL instead of leaving the streams[0] but if I somehow configured Shinobi to have HomeBridge to not direct stream, I got the ffmpeg error (though I verified I can load the m3u8 link in safari).

Also, can you share your Shinobi camera config.json to compare with what's in mine to know what you're expecting?

Thank you!

vectronic commented 3 years ago

Hi. Thanks for your detailed analysis. If you can wait a few days I’ll try to dig into it on the weekend.

vectronic commented 3 years ago

I've cleaned up the horrible embedded json produced by shinobi for both your config and mine in the attached zip.

Archive.zip

I can tell you a number of things, but no clear answer at this stage....

Firstly, 4:3 should be fine, this is what the plugin is hard coded to:

https://github.com/vectronic/homebridge-shinobi/blob/master/src/shinobiMonitorAccessory.ts#L71

Secondly I am pretty sure, unless the auto_host route is taken, I don't think it will work. The reason is that the streams[0] entry always seems to be a relative URL. I believe I never tested this as I always wanted to use a direct camera stream. (To be honest I thought I would be the only person ever using this plugin!).

In the auto_host scenario for yourself, I think it will only work if the details are 640x360@20fps as per the hard coded config above.

Even in the case of auto_host the plugin still needs to use FFmpeg to re-stream the feed into SRTP. I have ever only used RTSP as the FFmpeg source. I am unsure about using RTMP. And I am even more doubtful about HLS as a source. That said, FFmpeg is excellent at dealing with anything you give it as input.

The URL to your second stream appears in a different place in the shinobi config which this plugin doesn't consider: details.input_maps[0].fulladdress.

I think the plugin logic would need to change as follows:

If the above logic was implemented:

However you would still need to confirm that RTMP works if you setup the sub-stream to be 640x360@20fps. If you can configure your main-stream to this temporarily then you would see if using auto_host works for RTMP with these settings.

At some point also I should really make the resolution and framerate support better and automatically provide conversion when needed, even if the auto_host route is taken...

Let me know what you think of the above. I can make the code changes if you think it makes sense and looks like it will work for you...

vectronic commented 2 years ago

Closing due to no response.