Nikitenko Maxim (Sets88)

Personal page

Python - Get video from ActiveX surveillance camera

Recently i got task, i had to let someone to view cameras from DVR, but there were a problem, it is ActiveX DVR, to access to cameras you have to use Internet Explorer, and here is another problem, this organisation has only Linux installed.

Who ever tried to solve this problem, knows, that it is not easy to do.

I googled hard, but found nothing.

First thing i've done, i found mobile client for this DVR, i took ASee+ for IOS and turned Wireshark on:

I got packet with authorization, that what i was looking for, i took packet's content and saved it to file. Just to show you, i included captured file inside the script file, besides, it's abit easier to make changes like that, for example to switch camera on this DVR.

What script have to do:
- Connect on given port
- If error happends, shows message
- Send captured packet with authorization
- Get a video stream
- Send it using pipe to mplayer

Source code
#! /usr/bin/python

import socket
import sys
import subprocess

login = "admin"
passwd = "admin"
host = ""
port = 6060
if len(sys.argv) > 1:
    cameraid = chr(int(sys.argv[1]))
    print "Usage:\n%s camid" % sys.argv[0]

auth = '\x00\x00\x00H\x00\x00\x00\x00(\x00\x04\x00\x05\x00\x00\x00)\x008\x00%s\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00%s\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00%s\x00\x00' % (login.ljust(8, "\x00"), passwd.ljust(8, "\x00"), cameraid)
player_cmd = "mplayer -nocache -fps 3 -demuxer h264es -"
notify_cmd = "notify-send -t 1000"

class Camviewer(object):
    def __init__(self, auth=auth, host=host, port=port):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect(host, port)
        self.player_proc = subprocess.Popen(player_cmd.split(" "), stdin=subprocess.PIPE)

    def connect(self, host, port):
            self.sock.connect((host, port))
        except (socket.error, socket.timeout) as e:
            self.notify("Error", e.args[-1])

    def notify(self, header, body):" ") + [header, body])

    def send_msg(self, msg):

    def recive_msg(self, bcount=1500):
        return self.sock.recv(bcount)

    def play(self):
        while 1:
            buf = self.recive_msg()
            if len(buf) == 0:

if __name__ == "__main__":