Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-21

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
spellicer
Posts: 2
Joined: Sat May 11, 2013 5:17 am

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by spellicer »

Phoenix84 wrote: If you can see your cameras in ffmpeg, you should be able to see them in Zoneminder. However I noticed an weird behavior with ZM that I had to adjust for in the program.
ZM will disconnect and reconnect frequently when it starts to stream. Sometimes this confuses my program and it exits.
I adjusted for this by making sure all children are automatically restarted if they exit for some reason (unless the parent is terminated).
However this change is only in the latest version I just posted, 0.4.

If possible, see if you can add your changes into that version. You've already done the hard work by figuring out the login steps.
If you want to confirm this behavior before proceeding, you can do the following:
After starting the program, execute 'pgrep zmodopipe' or 'ps -A | grep zmodopope' to get the PIDs. You should see # channels + 1 processes (so if you only stream one channel, you'll see two processes).

Now, restart zoneminder and wait about 30 seconds, then execute the above pgrep/ps command again.
If one or more processes disappeared, or the PIDs changed, then that might be your problem.

I tried experimenting with the command-line options in the ZM settings, but I didn't notice any difference.
My initial version ran into this. I ended up looping the entire process (excluding finding the media port). Each channel will reconnect to control and media then start the stream.

I've done a little more exploration, and it seems like it might be related to the initial probe by zoneminder on the stream not being able to detect what the stream is. I'm looking
at some of the code in zm_ffmpeg_camera.cpp I believe and it is trying to probe the pipe and getting confused. I noticed this with ffmpeg as well. It can't probe unless I tell it
-f h264. Once it knows that, it can ascertain the resolution, fps, and whatnot. I started playing around with doing an additional pipe to ffmpeg after zmodopipe and writing
that to a pipe that zoneminder can look at. I initially did some testing of ffmpeg grabbing the pipe and writing to a file and that worked fine. I could pick up the pipe with ffmpeg
with -f h254 and output to a file with an .mp4 extension and then play the file. The problem is, I can't pick up the pipe from ffmpeg and write to another pipe. I'm kind of
clueless with ffmpeg and it seems to be because it can't put in a header and start writing the data (pipe related?). I thought I might be able to write the pipe with a different format
but can't seem to get the correct set of flags to write a simple mpeg stream or something else. While not ideal, I wouldn't mind piping through the two (zmodopipe and ffmpeg)
and then having zoneminder grab the final converted pipe. It seems like the stream I'm getting from the zmodo is full of all kinds of things that ffmpeg doesn't like, so I'm thinking
I can send it once through ffmpeg to clean it up. Again, not ideal, but I really didn't want to go through the trouble of recompiling zoneminder components.

I've also alternatively been looking into compiling zmodopipe to scrub the stream with ffmpeg and just outputting the cleaned up stream to a pipe output and then letting zoneminder
read this pipe. I'm looking through some exmaple libavcodec code to see if it's worth the trouble. A simple test to see if this is gonna work would be to get a working ffmpeg
command line that is something along the lines of ffmpeg -f h264 -i /tmp/zmodo0 -f <probably mpeg or something simple> <all the output stream parameters> /tmp/ffmpegpipe0
When I try that pipeline with ffmpeg -f h264 -i /tmp/zmodo0 -f h264 /tmp/ffmpegpipe0 it complains about not being able to write the header (I'm not sure of the exact error, I'm not
at the box at the moment). I'm assuming there are different containers and whatnot that are conducive to streams (pipes) as opposed to files due to using random access or other factors.
Phoenix84
Posts: 21
Joined: Sat Jun 25, 2011 7:20 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by Phoenix84 »

spellicer wrote:My initial version ran into this. I ended up looping the entire process (excluding finding the media port). Each channel will reconnect to control and media then start the stream.

I've done a little more exploration, and it seems like it might be related to the initial probe by zoneminder on the stream not being able to detect what the stream is. I'm looking
at some of the code in zm_ffmpeg_camera.cpp I believe and it is trying to probe the pipe and getting confused. I noticed this with ffmpeg as well. It can't probe unless I tell it
-f h264. Once it knows that, it can ascertain the resolution, fps, and whatnot. I started playing around with doing an additional pipe to ffmpeg after zmodopipe and writing
that to a pipe that zoneminder can look at. I initially did some testing of ffmpeg grabbing the pipe and writing to a file and that worked fine. I could pick up the pipe with ffmpeg
with -f h254 and output to a file with an .mp4 extension and then play the file. The problem is, I can't pick up the pipe from ffmpeg and write to another pipe. I'm kind of
clueless with ffmpeg and it seems to be because it can't put in a header and start writing the data (pipe related?). I thought I might be able to write the pipe with a different format
but can't seem to get the correct set of flags to write a simple mpeg stream or something else. While not ideal, I wouldn't mind piping through the two (zmodopipe and ffmpeg)
and then having zoneminder grab the final converted pipe. It seems like the stream I'm getting from the zmodo is full of all kinds of things that ffmpeg doesn't like, so I'm thinking
I can send it once through ffmpeg to clean it up. Again, not ideal, but I really didn't want to go through the trouble of recompiling zoneminder components.

I've also alternatively been looking into compiling zmodopipe to scrub the stream with ffmpeg and just outputting the cleaned up stream to a pipe output and then letting zoneminder
read this pipe. I'm looking through some exmaple libavcodec code to see if it's worth the trouble. A simple test to see if this is gonna work would be to get a working ffmpeg
command line that is something along the lines of ffmpeg -f h264 -i /tmp/zmodo0 -f <probably mpeg or something simple> <all the output stream parameters> /tmp/ffmpegpipe0
When I try that pipeline with ffmpeg -f h264 -i /tmp/zmodo0 -f h264 /tmp/ffmpegpipe0 it complains about not being able to write the header (I'm not sure of the exact error, I'm not
at the box at the moment). I'm assuming there are different containers and whatnot that are conducive to streams (pipes) as opposed to files due to using random access or other factors.
Yup. I have to use -f h264 on the ffmpeg command-line as well for it to be able to read it. I haven't had to do that for Zoneminder though. I usually have to wait 30 seconds or so for the stream to become visible in ZM.
Just make sure you have the Capture Width and Height set correctly (and 24 bit color). Mine is 704x480.

You can try using ffmpeg to stream the feed over multicast UDP:
ffmpeg -re -f h264 -i /tmp/zmodo0 -vcodec mpeg4 -b:v 500k -f mpegts udp://239.1.1.1:1234

I know that works with VLC (open a new network stream and enter: udp://@239.1.1.1:1234 and it should start streaming),
but I haven't tested multicast streaming with Zoneminder.
Which version of Zoneminder are you using? I'm using 1.25.
hvc123
Posts: 9
Joined: Mon May 25, 2009 8:04 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by hvc123 »

Hi

i was wondering if someone could help. i have a swann dvr-1200 4 channel. i have successfully got the mobile port working with this
"zmodopipe -s 172.16.0.100 -p 18004 -c 1 -c 2 -u username -a password -m 1"

which is great but its limited to 5fps and a really rubbish codec, kinder pointless

i have compiled the new version and tried all -m 1-8 and the only one that will work is still m1. i have also tried to change the port from 18004 to 9000 still no go

Thanks
hvc123
Posts: 9
Joined: Mon May 25, 2009 8:04 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by hvc123 »

any 1 know if i have to try a differnet screen size.... i.e not 320 x240 ?
mattrob
Posts: 1
Joined: Sat Jun 01, 2013 9:41 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by mattrob »

Hello!

I'm trying to get this working with my Zmodo DVR. The model on the bottom is the D9104BH, which I assumed to be the same as the DVR-H9104. (Maybe this is an incorrect assumption)

I'm using the command: ./zmodopipe -s 192.168.1.142 -p 7050 -c 1 -u Admin -a 111111 -m 1
(I'm using port 7050 - the mobile port)
and I get error messages saying the login failed.

In IP Cam Viewer, the "Zmodo DVR-8104UV Mobile Port" works with port 7050, and I can see video.

Am I doing something completely dumb?

Thanks!
TheCase
Posts: 3
Joined: Tue Nov 15, 2011 11:32 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by TheCase »

mattrob wrote:Hello!

I'm trying to get this working with my Zmodo DVR. The model on the bottom is the D9104BH, which I assumed to be the same as the DVR-H9104. (Maybe this is an incorrect assumption)

I'm using the command: ./zmodopipe -s 192.168.1.142 -p 7050 -c 1 -u Admin -a 111111 -m 1
(I'm using port 7050 - the mobile port)
and I get error messages saying the login failed.

In IP Cam Viewer, the "Zmodo DVR-8104UV Mobile Port" works with port 7050, and I can see video.

Am I doing something completely dumb?

Thanks!
I've got a H9108V (D91088H) that is working in the mobile app at port 7050 as well.

Have you tried mode 5? -m 5 seems to work for me... if a streaming screen of dots is what one is to expect when using -v

I still don't get anything but idle output from ZoneMinder, however. Not sure what else to try. I got nothing from the media port (6050)
RickWakeman
Posts: 1
Joined: Fri Jun 14, 2013 12:40 am

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by RickWakeman »

I am using the ZMD-DD-SAN8. I have a ZoneMinder and zmodopipe installed, and can connect using the -m 5 argument but I don't get a picture in the Zoneminder console. This DVR works in IP Cam Viewer using "Zmodo DVR w/ Mobile Port". Any ideas?
Last edited by RickWakeman on Sun Jun 16, 2013 1:33 am, edited 1 time in total.
hvc123
Posts: 9
Joined: Mon May 25, 2009 8:04 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by hvc123 »

here is an interesting page if any one is interested in how weak the swann dvrs and such are http://console-cowboys.blogspot.co.uk/2 ... chive.html
also anyone wanna try to help me pull an rtsp stream from the cslistner app with wireshark ? im a proper noob with ws
hvc123
Posts: 9
Joined: Mon May 25, 2009 8:04 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by hvc123 »

if anyone is slightly interested the swann DVR4-1200 has a file /m.html which redirects you too rtsp://DVRIP/011.3gp but this does not work..
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by jameswilson »

Interesting topic. Any chance this being rolled into a future 1.26.x?
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
dookie
Posts: 6
Joined: Thu Oct 10, 2013 3:24 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by dookie »

UPDATE: So I tinkered around with IPCAM Viewer on my android again. I tried the ZMODO DVR Mobile port as the cam. and BAM. I'm getting video. but not using zmodopipe yet.

has anyone used this successfully with a MonoPrice DVR? The dvr came with an android app called KMEye from Meyetech.

I could seriously use a little help here :) network analyzing/apk decompiling

the DVR model is a DVR-0401. It is a shenzen (SINGMATE?) dvr. I have run through all of the zmodopipe options with no luck. I have also tried various connections with vlc and even used the Monoprice DVR option(s) in IPCAM Viewer. Nothing.

I monitored the network traffic via wireshark while using the KMeye android app. I can see the connection to my mobile port (15900) from my device and the returns from the dvr. I can read, sadly, my username and IPaddress in clear text. I can even see the dvr returning the dvr firmware version and a bit of other data in clear text.

after the phone has connected and authenticated, I then notice that my android device connects to the dvr mobile port (15900) on using a new port for each video channel. Actually, the DVR is now streaming the 4 feeds on 4 individual ports.

example connection: very VERY simple example of the type of net traffic i'm seeing

Code: Select all

init:  phone (60484) -> DVR (15900) username/pw
init:  dvr (15900) -> (60484) firmware/model info
playing channel 1 dvr (15900) -> (60493)
playing channel 2 dvr (15900) -> (60494)
playing channel 3 dvr (15900) -> (60495)
Of course, any command from the app is also sent on the original (60483) port.

Now, the fun part is that the 4 dvr stream ports are different port numbers each connection, so I can't guess what ports are active. I cannot find any hex/ascii that relates to any of the new port numbers, which probably means it's encoded in some for array or whatever.

MORE FUN! - decompiled the KMEye APK!!!
I decompiled the android .apk. I have both the .smali files AND have gotten far enough to get most of the actual source code pulled out. I have no problem in sharing it.. just PM me.

I can't re-compile the source code yet, so I can't put any kind of debug into the code to find out what it is "REALLY" doing. I'm still unsure if the app or the dvr is setting the 4 new port numbers, but I learn towards the app

anyone have any ideas?
dookie
Posts: 6
Joined: Thu Oct 10, 2013 3:24 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by dookie »

dookie wrote:UPDATE: So I tinkered around with IPCAM Viewer on my android again. I tried the ZMODO DVR Mobile port as the cam. and BAM. I'm getting video. but not using zmodopipe yet.
UPDATE 2: after looking through the IPCAM viewer code, comparing to zmodopipe and then watching the wireshark logs, the login message seems to match 100%.

However, it appears that the zmodopipe checks after sending the auth packet aren't getting... quite what they want. I simply commented out the returns so that I might get past some of this as a guess.... (I haven't done a thorough comparison of the logs from ipcamviewer and zmodopipe yet...takes a bit ;)

I now get the dvr firmware version number, etc... back from the dvr. so at least it is actually authenticating.

I still don't get anything in ZM. However, a cursory glance at the tcpdump after connecting with zoneminder seems to show similar packet structures as with IPCAM (i.e. seeing large packet sizes).

I've tried using ffmpeg to multicast the pipe, but vlc doesn't show me anything...
ffmpeg -re -f h264 -i /tmp/zmodo3 -vcodec mpeg4 -b:v 500k -f mpegts udp://230.1.1.1:1234 (as shown in an earlier post)

Now, I AM doing all of this using the VMWare ZM appliance, maybe there's something else funky...

I'm THIS close to dumping the dvr and just buying a few IP cams :(
dookie
Posts: 6
Joined: Thu Oct 10, 2013 3:24 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by dookie »

dookie wrote:
dookie wrote:UPDATE: So I tinkered around with IPCAM Viewer on my android again. I tried the ZMODO DVR Mobile port as the cam. and BAM. I'm getting video. but not using zmodopipe yet.
UPDATE 2: after looking through the IPCAM viewer code, comparing to zmodopipe and then watching the wireshark logs, the login message seems to match 100%.
SUCCESS! (Sorta)
UPDATE 3: (yeah, I feel like I'm talking to myself.)

I determined that the messaging was a bit different. I had to handle 2 or 3 additional messages coming from this DVR and strip off at least one additional header before I could start getting data from the pipe.

Now, I can create a file using: ffmpeg -i /tmp/zmododvr3 -vcodec copy -y cam.mp4
The file is quite sped up but watchable.

I Can see video in zoneminder. The Resolution is 352x240 on this mobile port. The down side is, there is something quite wrong. The image is basically still, but updates every so often. I have also noticed that the zmodopipe program reports that the pipe was broken on occasion.

Frame rate is around 7fps, which is much lower than with IPCAM Viewer, so that is concerning me.

I'm attaching the update zmodopipe application which contains my changes. I haven't cleaned up all my code yet and it is certainly not finished... BUT, it has at least gotten me to view data in zoneminder.

I added the Device as option 9 in the selection list. run as normal.

So that you don't confuse this version with the current zmodo pipe release... Compile as follows:

gcc zmodopipeMonoPriceMod.c -o zmodopipeMonoPriceMod

Run with ./zmodopipeMonoPriceMod -n zmododvr -s <IP> -p <mediaport> -u <username> -a <yourpassword> -c 4 -v -m 9


I WOULD GREATLY appreciate feedback or suggestions as to why I am getting such poor performance at this point where IPCAM Viewer is much more reliable.

just to keep a few notes for myself:
1. to fix the probe cameras error on Ubuntu 13.04: edit /usr/share/zoneminder/skins/classic/views/monitorprobe.php - Replace: $command = "arp -a"; with $command = "/usr/sbin/arp -a";

2. to fix startup propblems: edit /etc/init.d/zoneminder
add: sleep 15 just above the zmfix -a line

3. if you have the error: "shared data size conflict" in your logs and are on a 32bit machine, look at: lachlanmiskin com/blog/2012/06/24/zoneminder-shared-data-size-conflict-in-shared_data-for-monitor/ (you'll have to fix the link, since I can't post them...)
don't see this error on my 64bit machine

4. having problems with shmgets in the logs?
echo kernel.shmmax = 536870912 >/etc/sysctl.d/60-kernel-shm.conf
sysctl -p
ipcs -l
--then restart zoneminder.

also note, it may take up to 1 minute for the video to show up currently.
Attachments
zmodopipeMonoPriceMod.zip
(9.9 KiB) Downloaded 407 times
dookie
Posts: 6
Joined: Thu Oct 10, 2013 3:24 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by dookie »

updated patch -
added: MonoPrice Dvr 0401 Media Port support

Supports Monoprice dvr-0401 Media Port and possibly other zmodo models that have come out in the last few years.

I can now get video from the pipe in zoneminder, but it still only refreshes images at about 15 second intervals, BUT, it is more stable than the mobile port.

I created a video file using ffmpeg and then played it back with vlc. I expected a higher resolution video, but vlc produced this information:
file created with: ffmpeg -i /tmp/zmododvr3 -vcodec copy -y cam.mp4
VLC File Properties:
Codec: H264 - MPEG-4 AVC (part 10) (avc1)
Resolution: 352x240
Frame rate: 25
Decoded format: Planar 4:2:0 YUV
I know very little about video formats, but since the h264 handling is a little old in zmodopipe,
there may be a decoding issue. I'm only seeing about 6-7fps in zoneminder.

This is definitely still early in the testing. I'll continue to look through the actual video data. I do know that there is a message that gets returned immediately following the login message. It doesn't contain much, but it does have the value: MDVR96NT_2_R, which appears to have something to do with video? This message also may state whether the login was successful or not.... still checking that out.

The immediate next message APPEARS to be the video message, but this particular one has about 8 bytes at the beginning: 33 30 64 63 48 32 36 34 which is: 30dcH264 in ascii. I notcied something similar in a message in one of the mobile port messages, so maybe this needs removed or the entire message needs tossed... this dcH264 value shows up in later messages periodically.

use -m 10 to access this dvr's media port.
Attachments
zmodopipeMonoPriceMod_v0_4_3.zip
0.4.3 - support monoPriceDVR 0401 Media Port
(10.71 KiB) Downloaded 391 times
dookie
Posts: 6
Joined: Thu Oct 10, 2013 3:24 pm

Re: Working QSee/Swann/Zmodo DVR support! - Updated 2013-04-

Post by dookie »

one more post for today... :twisted:

I'm including the wireshark logs for the testing with the Media port. (don't worry about the password. it's a temp one for this effort). I'm trying to determine what the issue with the H264 data coming out of the pipe. it's definitely not correct but I don't know jack about it...

I also had to make an updated version to ensure I got rid of the extra message or 2 the dvr sends after login. (see previous thread).

I'm also going to paste a snippet of decompiled code from IPCAM. If phoenix feels i should pull this... then I will. It's not complete/compile-able in any way. I'm posting it as I think it's handling the h264 video decoding, but i'm not 100% sure what it's doing. (partially because the decompile process doesn't always return accurate code..). This code, I believe, is what's called to handle the decoding of the h264 stream.

NOTE: i want to point out that this snippet is at least partially searching for "H264" in the data. The byte locations of H and 2 (4 and 5 respectively) match with the wireshark traffic. So I'm fairly certain that this code may look for the H264 "string", then return a pointer/byte location to the proper start of the H264 video... complete guess though.

Code: Select all

int getDataPacket(InputStream paramInputStream, byte[] paramArrayOfByte, int paramInt, Ptr<Byte> paramPtr)
    throws IOException
  {
    byte[] arrayOfByte = ResourceUtils.getReadBuf();
    int i = 0;
    if (ResourceUtils.readIntoBuffer(paramInputStream, arrayOfByte, 0, 16) < 16)
      return -1;
    int j;
    int n;
    label138: int k;
    if (((arrayOfByte[4] == 72) && (arrayOfByte[5] == 50)) || ((arrayOfByte[2] == 119) && (arrayOfByte[3] == 98)))
    {
      if ((arrayOfByte[4] != 72) || (arrayOfByte[5] != 50))
        break label216;
      paramPtr.set(Byte.valueOf(arrayOfByte[4]));
      j = 0xFF & arrayOfByte[8] | (0xFF & arrayOfByte[9]) << 8;
      if ((arrayOfByte[12] == 8) || (arrayOfByte[12] == 16))
        break label196;
      n = 0;
      if (n == 0)
        break label209;
      if (arrayOfByte[12] != 8)
        break label202;
      k = 16;
    }
    while (true)
    {
      if (k > 0)
        ResourceUtils.skipBytes(paramInputStream, k);
      if (paramInt + j <= paramArrayOfByte.length)
        break label282;
      return -9;
      if (i > 32)
        return -1;
      i++;
      break;
      label196: n = 1;
      break label138;
      label202: k = 24;
      continue;
      label209: k = 8;
      continue;
      label216: if ((arrayOfByte[2] != 119) || (arrayOfByte[3] != 98))
        break label280;
      paramPtr.set(Byte.valueOf(arrayOfByte[2]));
      j = -8 + (0xFF & arrayOfByte[6] | (0xFF & arrayOfByte[7]) << 8);
      k = 0;
    }
    label280: return -1;
    label282: if (ResourceUtils.readIntoBuffer(paramInputStream, paramArrayOfByte, paramInt, j) < j)
      return -10;
    int m = j % 8;
    if (m > 0)
      ResourceUtils.skipBytes(paramInputStream, 8 - m);
    return j;
  }
And this is the calling code:

Code: Select all

 while (true)
      {
        InputStream localInputStream2;
        byte[] arrayOfByte2;
        Socket localSocket;
        InputStream localInputStream1;
        ByteBuffer localByteBuffer;
        byte[] arrayOfByte1;
        Ptr localPtr;
        int i;
        boolean bool;
        int j = getDataPacket(localInputStream1, arrayOfByte1, 0, localPtr);
        if (j < 0)
        {
          WebCamUtils.setLingerResetConnection(WebCamUtils.g_bDefaultLingerResetConnection);
          if ((localObject1 == null) || (!paramBoolean))
            disconnect();
          if ((localObject1 != null) && (!paramBoolean) && (!Thread.currentThread().isInterrupted()))
            ThreadUtils.sleep(1000L);
          return null;
        }
        if (((Byte)localPtr.get()).byteValue() == 72)
        {
          Bitmap localBitmap = decodeVideoFrame(localByteBuffer, 0, j, paramInt1, paramInt2);
          localObject1 = localBitmap;
        }
        if (localObject1 == null)
          i++;
      }
    }

I'm hoping someone can point me to what's going on quicker than I can figure it out.
Attachments
zmodopipeMonoPriceMod_v0_4_4.zip
Updated MP DVR-0401 Media port to handle 2 additional returns before video. still beta!
(11.41 KiB) Downloaded 426 times
shark_dump_1381758575IPCAM_mobileport2.zip
wireshark monoprice dvr media port capture log
(250.15 KiB) Downloaded 411 times
Post Reply