
TaniDVR
A tool for DVRs based on the DVR-IP protocol.

Copyright (c) 2011-2015 Daniel Mealha Cabrita
Available under the GNU GPL v3 license (see "COPYING" file).



What is TaniDVR?
----------------

TaniDVR is a CLI tool 'tanidvr' for accessing DVRs / IP cameras
used for CCTV surveillance systems based on the DVR-IP protocol (port 37777/TCP).

Those are quite inexpensive Linux-based OEM DVRs made available by several
distinct brands around the world.
All those DVRs, regardless their branding, are produced by this company:
Zhejiang Dahua Technology Co., Ltd.

Unfortunately those DVRs do not (*) come with native Un*x-compatible (Linux, *BSD..)
clients, and its web interface often only works with a certain web browser for a
certain proprietary OS.

(*) Starting from 2012-2013 a, x86-only Wine-based, Linux port of the
Windows OS DVR client was made available from Dahua to DVR OEMs.
Compared to the native Windows OS client,
TaniDVR is more resilient to firmware bugs and network problems,
and TaniDVR+MPlayer use a fraction of CPU processing power
while displaying multiple videos simultaneously.

So now you can finally access (watch, record) the videos from such DVRs
from a proper OS.



Is my DVR / IP camera compatible?
---------------------------------

If your DVR works with the DVR-IP protocol it is expected to work.

If you want to check whether your DVR supports that, you may verify
if your DVR is listening to the port 37777/TCP (99% of cases).
Those DVRs are advertised as having an embedded Linux running, support
an internal SATA HD, support audio sampling etc and there are models
with 4, 8 and 16 channels (and possibly other variations).

Those DVRs are sold under a number of brands, including:

Apollo
Acorn F&S
C2Max
Dahua
DVR365
GWave
Intelbras
IntelliPix
Mace S. P.
New Surway
NextVision
Q-See
WatchNet
... etc

TaniDVR is confirmed to work with the following DVRs / IP cameras:

Dahua IPC-HDB3200C
Dahua DH-DVR0404HF-AN
Dahua DH-NVR3816
Dahua DH-DVR1604HF-U-E
Intelbras VD 8E 240
...
(see updated list at TaniDVR's website)

Some DVRs with (very) old firmware may have compatibility problems
due to old implementations of Dahua's own DVR-IP protocol.
Such problems may (or may not) be solved with firmware upgrade.



How do I use 'tanidvr'?
-----------------------

Some examples:

Display the available options:
$ tanidvr --help

Show some information about the DVR:
$ tanidvr -m 0 -t 192.168.0.12 -u admin -w secret1234

Record a video to a file:
$ tanidvr -m 1 -t 192.168.0.12 -u admin -w secret1234 -c 2 -f camera2.mkv

Play the video in realtime with an external player:
$ tanidvr -m 1 -t 192.168.0.12 -u admin -w secret1234 -c 2 | mplayer -cache 32 - 2>/dev/null



'dhav2mkv' tool (DHAV video to MKV format converter)
----------------------------------------------------

'dhav2mkv' is a standalone tool which converts DHAV(H.264) video to MKV(H.264) video.
The routines are the same as the ones used by 'tanidvr' (when the chosen
output container format is MKV, which is the default mode), thus this tool
is _redundant_ is fed directly from tanidvr (from a pipe, for ex.).

dhav2mkv _only_ operates at media container level, thus the H.264 data is _exactly_
as provided by the DVR (with all its bugs).

dhav2mkv 1.4.0 allowed, but not required, to specify a channel number.
dhav2mkv <= 1.3.0 required to specify a channel number.

Current dhav2mkv version does not support specifying a channel number.
It assumes the stream holds a single channel,
instead of a theoretically possible 'n' multiplexed channel stream.
The reason that option support was dropped is that some DVRs generate
DHAV streams with incorrect channel number such way that
two or more channels collide with the same channel number,
what makes impossible to differentiate one from another.
Also there's the fact that DHAV multi-channel multiplexing
is not used in practice.


Cases for using dhav2mkv:

- To convert already-existing DHAV files to MKV.
  Those files may be tanidvr-generated or generated by the software included
  with the DVR itself (due to legacy, or by choice).
  --
  DHAV files are only (currently) playable with the software included with
  the DVR, while MKV is a modern, open and commonly supported container format.
  Using a standard container also allows the video to be _recompressed_ for
  better storage usage.

- To create a video hub (a video repeater), propagating DHAV media which,
  at the end-point, is converted to MKV.
  --
  The DVR itself supports a very limited number of simultaneous connections
  (usually slighty more than hardware channels). Also, near the maximum
  active connections the DVR tends to be even more unstable. Direct
  connections to the DVR should be kept to essencial minimum.
  --
  dhav2mkv allows the conversion of ongoing DHAV video (doing that with
  MKV is not viable for technical reasons). Any stream starting point
  (down to byte granularity) is acceptable. Also, temporary source
  interruption with lost/corrupted data suffers automatic resync
  (what is also done by 'tanidvr', when outputting MKV data).
  --
  A simple media hub may be implemented with existing complementary
  software such as ncat (from nmap project) with its '--broker' option.

- For Digital Forensics. Some police forces already use dhav2mkv
  for last-step recovering of video evidence from apprehended DVRs.


Some examples:

Convert an existing DHAV file to MKV:
$ dhav2mkv -i MyVideo.dhav -o MyVideo.mkv

Using dhav2mkv instead of tanidvr's internal routines:
NOTE: NOT NECESSARY in practice since tanidvr can output MKV directly.
      It is shown only for didactic purposes.
$ tanidvr -n 0 -m 1 -t 192.168.0.12 -u admin -w secret1234 -c 2 | dhav2mkv > channel_2_video.mkv

Simple media server and some clients:
NOTE: INSECURE. NOT to be implemented as-is.
      It is shown only for didactic purposes.
(server at 192.168.20.1)
$ tanidvr -n 0 -m 1 -t 192.168.0.12 -u admin -w secret1234 -c 5 | ncat --broker -l 192.168.20.1 2000
(clients ; same/other host)
$ ncat --recv-only 192.168.20.1 2000 | dhav2mkv | mplayer -cache 32 -
$ ncat --recv-only 192.168.20.1 2000 | dhav2mkv > channel_5_realtime_backup.mkv
$ ncat --recv-only 192.168.20.1 2000 > channel_5_realtime_backup.dhav



(text ends here)

