Connecting zoneminder to Swann DVR4-1300 Media Port

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Connecting zoneminder to Swann DVR4-1300 Media Port

Post by kennbr34 »

I have an old DVR that I want to setup to work with ZoneMinder. Right now I have it setup to send the TV-Out to my PC with a capture card and monitor it thorugh zoneminder like that, but I don't like that every channel is brought on one signal to be treated as a single monitor by zoneminder. I've been slowly upgrading to IPcams, but still have my outdoor cameras wire up through the DVR.

It has a "media port" on 18004 but I don't have any idea what protocol it's using. I've tried to add it with zoneminder with no luck, but I have an application on my tablet called "IPCam Viewer" that views them fine. I tried to contact the author, but of course he didn't respond with any help (thanks, jerk) so how this application is streaming the channels is a mystery to me.

Well, I know a little bit about computer here and there, so I used WireShark to sniff the TCP stream and I got a rough idea of how the streaming works for the DVR. Basically the viewing device sends a "command" to the box consisting of the channel ID and the username, and then the DVR begins sending back an H.264 stream. The command looks something like this...

Code: Select all

00000000  00 00 00 40 00 00 00 00  29 00 38 00 61 64 6d 69  |...@....).8.admi|
00000010  6e 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |n...............|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000044
I don't quite remember which bite was the one to control the channel, but it counts from 0-3 so it's somewhere in the first few bytes that I'm specifying. So then it sends back a H.264 stream ( though I can barely get it to play in anything besides mplayer ).

(Just a snippet)

Code: Select all

00000000  00 00 00 14 00 00 00 00  28 00 04 00 03 00 07 00  |........(.......|
00000010  2a 00 04 00 01 00 00 00  00 00 00 84 00 00 00 00  |*...............|
00000020  46 00 48 00 42 30 46 33  33 42 37 33 39 44 45 37  |F.H.B0F33B739DE7|
00000030  36 44 37 39 00 00 00 00  00 00 00 00 00 00 00 00  |6D79............|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 56 31 32 30  38 32 37 00 00 00 00 00  |....V120827.....|
00000060  00 00 00 00 00 00 00 00  04 00 00 00 41 00 04 00  |............A...|
00000070  01 00 00 00 c7 00 28 00  00 00 00 00 48 32 36 34  |......(.....H264|
00000080  00 7d 00 00 40 01 f0 00  05 18 00 00 00 00 00 00  |.}..@...........|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 11 58 00 00 00 00  63 00 0c 00 00 00 00 00  |...X....c.......|
000000b0  00 00 00 00 00 00 00 00  64 00 40 11 00 00 00 01  |........d.@.....|
000000c0  67 42 e0 14 db 05 07 c4  00 00 00 01 68 ce 30 a4  |gB..........h.0.|
000000d0  80 00 00 00 01 06 e5 01  fa 80 00 00 00 01 65 b8  |..............e.|
000000e0  00 01 f5 f8 2c 50 ae 1f  02 09 17 70 60 00 13 54  |....,P.....p`..T|
000000f0  07 fd 1a 87 cc 8a 68 99  d2 f5 e1 c7 96 fe 27 7f  |......h.......'.|
00000100  df 85 48 9c bc 4d fc 1a  8b 05 81 bb e9 92 a0 e9  |..H..M..........|
00000110  63 68 f1 4f de ee 21 53  49 05 f0 47 bc 11 8a 1c  |ch.O..!SI..G....|
00000120  80 04 96 d2 63 c6 da 29  ca 18 ee 59 a7 d4 0c 38  |....c..)...Y...8|
00000130  b3 23 35 1f fd 9a 0d 4e  ba 92 bc fd fb 12 89 93  |.#5....N........|
00000140  73 2a ab ca e9 4e c7 c6  2e 4f 61 e6 02 0e e2 0d  |s*...N...Oa.....|
00000150  36 c9 d1 9d c4 78 77 e7  b5 18 6f df ee 74 0d 29  |6....xw...o..t.)|
00000160  e1 08 5f d4 03 f5 46 c6  2b 47 67 bd 4f 89 16 3e  |.._...F.+Gg.O..>|
Now I've obtained this basically by doing...

Code: Select all

cat ipcommand | nc 192.168.1.3 18004 > ipcam_out
I thought maybe appending it on each request was needed so I tried...

Code: Select all

cat ipcommand | nc 192.168.1.3 18004 >> ipcam_out
Thinking it just would send updated packet information to be appended each time, but haven't really been able to get any media player to open it and play it successfully.


So any ideas? I'm going to upgrade to IPcams eventually but just thought it would be fun to figure this out.
Last edited by kennbr34 on Thu Apr 12, 2018 7:40 pm, edited 1 time in total.
bbunge
Posts: 2923
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Connecting zoneminder to swan media port

Post by bbunge »

Did you try VLC with your DVR stream? If you can get it to work in VLC it will work in Zoneminder.
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Re: Connecting zoneminder to swan media port

Post by kennbr34 »

bbunge wrote: Thu Apr 12, 2018 12:48 am Did you try VLC with your DVR stream? If you can get it to work in VLC it will work in Zoneminder.
Yeah it just threw errors about the stream not having a frame and some kind of codec error I didn't understand, but it would show a frame of video and then crash.

To be specific Swann DVR4-1300 model

But luckily I found a project from someone trying to make tools to connect to a different Swann model, and he had found a write-up on the wiki here using zmodopipe. I used this write-up to connect to my Swann DVR on the mobile port.

https://wiki.zoneminder.com/Zmodopipe

I have 3 cameras so I changed my configuration for ffserver to look more like this...

Code: Select all

Port 8090

#RTSPPort 8554
#HTTPPort 8554

BindAddress 0.0.0.0

MaxHTTPConnections 2000

MaxClients 1000

MaxBandwidth 9000

CustomLog -


NoDaemon





<Feed feed1.ffm>

File /tmp/feed1.ffm
FileMaxSize 200K

ACL allow 127.0.0.1

</Feed>

<Stream test.mjpg>
Feed feed1.ffm
Format mpjpeg
VideoFrameRate 10
VideoSize 320x240
VideoBufferSize 40
VideoGopSize 12
VideoBitRate 1200
AVOptionVideo flags +global_header
NoAudio
</Stream>

<Feed feed2.ffm>

File /tmp/feed2.ffm
FileMaxSize 200K

ACL allow 127.0.0.1

</Feed>

<Stream test2.mjpg>
Feed feed2.ffm
Format mpjpeg
VideoFrameRate 10
VideoSize 320x240
VideoBufferSize 40
VideoGopSize 12
VideoBitRate 1200
AVOptionVideo flags +global_header
NoAudio
</Stream>

<Feed feed3.ffm>

File /tmp/feed3.ffm
FileMaxSize 200K

ACL allow 127.0.0.1

</Feed>

<Stream test3.mjpg>
Feed feed3.ffm
Format mpjpeg
VideoFrameRate 10
VideoSize 320x240
VideoBufferSize 40
VideoGopSize 12
VideoBitRate 1200
AVOptionVideo flags +global_header
NoAudio
</Stream>

<stream stat.html>
Format status
</stream>
For some reason the stream needs to have a "test" prefix that then has a number following it. Wouldn't work if I changed to "ch1.mjpg" for example.

You also want to make sure to specify the VideoBitRate, otherwise it defaults to 64. In my case I just read the information from ffmpeg to find the bitrate of the stream zmodopipe was dumping and set it to that, so 1200.

Then I just launch the zmodopipes and ffserver with the ffmpeg commands forked via this bash script. Obviously the user and password should be changed. If you don't have a password set, you need one for this app to work.

Code: Select all

kenny@AMD:~$ cat ./dvr_connect 
#!/bin/bash

CODEC_OPTS=''

./zmodopipe -s 192.168.1.3 -p 18004 -c 1 -u user -a pass -m 1 > /dev/null 2>&1 &
./zmodopipe -s 192.168.1.3 -p 18004 -c 2 -u user -a pass -m 1 > /dev/null 2>&1 &
./zmodopipe -s 192.168.1.3 -p 18004 -c 3 -u user -a pass -m 1 > /dev/null 2>&1 &

ffserver -f /etc/ffserver2.conf > /tmp/ffserver.log 2>&1 &

ffmpeg -i /tmp/zmodo0 $CODEC_OPTS http://localhost:8090/feed1.ffm > /tmp/zmodoffmpeg1 2>&1 &
ffmpeg -i /tmp/zmodo1 $CODEC_OPTS http://localhost:8090/feed2.ffm > /tmp/zmodoffmpeg2 2>&1 &
ffmpeg -i /tmp/zmodo2 $CODEC_OPTS http://localhost:8090/feed3.ffm > /tmp/zmodoffmpeg3 2>&1 &
These links may also interest people with other DVR models that zmodopipe can work with...

https://github.com/kz/swanntools
viewtopic.php?t=18137
sparklee
Posts: 7
Joined: Sun Jun 13, 2021 7:23 pm

Re: Connecting zoneminder to Swann DVR4-1300 Media Port

Post by sparklee »

Hi... I am trying replicate what you have done. It appears that you have two files. Where exactly are those files suppose to go once created?
Post Reply