Common security network camera port and RTSP address

Hikvision
Default IP address: 192.168.1.64/DHCP username admin password set
Port: “HTTP port” (default is 80), “RTSP port” (default is 554), “HTTPS port” (default 443) and “service port” (default 8000), ONVIF port 80.
RTSP address: rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream
Description:
Username: The username. For example admin.
Password: password. For example 12345.
Ip: is the device IP. For example, 192.0.0.64.
Port: The port number defaults to 554. If it is the default, it can be left blank.
Codec: There are several types of h264, MPEG-4, and mpeg4.
Channel: The channel number, starting at 1. For example, channel 1 is ch1.
Subtype: The stream type, the main stream is main, and the auxiliary stream is sub.
For example, request the main stream of Haikang camera channel 1, Url is as follows
Main stream:
Rtsp://admin:12345@192.0.0.64:554/h264/ch1/main/av_stream
Substream:
Rtsp://admin:12345@192.0.0.64/mpeg4/ch1/sub/av_stream

Dahua
Default IP address: 192.168.1.108 Username/password: admin/admin
Port: TCP port 37777/UDP port 37778/http Port 80/RTSP Port number defaults to 554/HTTPs 443/ONVIF Function is off by default, port 80
RTSP address: rtsp://username:password@ip:port/cam/realmonitor?channel=1&subtype=0
Description:
Username: The username. For example admin.
Password: password. For example admin.
Ip: is the device IP. For example, 10.7.8.122.
Port: The port number defaults to 554. If it is the default, it can be left blank.
Channel: The channel number, starting at 1. For example, channel 2 is channel=2.
Subtype: The stream type, the primary stream is 0 (ie subtype=0), and the secondary stream is 1 (ie subtype=1).
For example, request the secondary stream of channel 2 of a device, Url is as follows
Rtsp://admin:admin@10.12.4.84:554/cam/realmonitor?channel=2&subtype=1

Xiongmai / Jufeng
Default IP address: 192.168.1.10 User name admin Password is empty
Port: TCP port: 34567 and HTTP port: 80, onvif port is 8899
RTSP address: rtsp://10.6.3.57:554/user=admin&password=&channel=1&stream=0.sdp?
10.6.3.57 This is the IP of the connected device
554 This is the port number of the RTSP service, which can be changed in the network service of the device.
User=admin This is the login username of the device.
Password= password is empty
Channel=1 first channel
Stream=0.sdp? Main stream
Stream=1.sdp? Secondary stream
Image capture address: http://ip/webcapture.jpg?command=snap&channel=1

Tianshitong
Default IP address: 192.168.0.123 User name admin Password 123456
Port: http port 80 data port 8091 RTSP port 554 ONVIF port 80
RTSP address: primary stream address: rtsp://192.168.0.123:554/mpeg4
Substream address: rtsp://192.168.0.123:554/mpeg4cif
Address that requires a password: Main stream rtsp://admin:123456@192.168.0.123:554/mpeg4
Substream rtsp://admin:123456@192.168.0.123:554/mpeg4cif
Photo capture address: http://ip/snapshot.cgi

Zhongwei/Shangwei
Default IP Address: DHCP Default User Name admin Default Password Empty
RTSP address: rtsp://0.0.0.0:8554/live1.264 (secondary stream)
Rtsp://0.0.0.0:8554/live0.264 (main stream)

Jiu’an
RTSP address: rtsp://IP:port(website port)/ch0_0.264 (main stream)
Rtsp://IP:port(website port)/ch0_1.264 (substream)

TECH/YOOSEE
Default IP address: DHCP username admin password 123
RTSP address: primary stream: rtsp://IPadr:554/onvif1
Secondary stream: rtsp://IPadr:554/onvif2
Onvif port is 5000
The port discovered by the device is 3702.

V380
Default IP address: DHCP username admin password empty /admin
Onvif port 8899
RTSP address: main stream rtsp://ip//live/ch00_1
Substream rtsp://ip//live/ch00_0

Yushi
Default IP address: 192.168.0.13/DHCP default username admin and default password 123456
Port: HTTP 80/RTSP 554/HTTPS 110(443)/onvif port 80
RTSP address: rtsp://username:password@ip:port number/video123 123 corresponds to 3 streams

Heaven and earth
Default IP address: 192.168.1.2 User name “Admin”, password “1111”
Onvif port number “8080”
RTSP address: rtsp://192.168.1.2

Dragon / JVT
Default IP address: 192.168.1.88 Default username admin Default password admin
RTSP address:
Primary stream address: rtsp://IP address/av0_0
Secondary stream address: rtsp://IP address/av0_1
Onvif port 2000
Image capture address: http://ip/capture/webCapture.jpg?channel=1&FTpsend=0&checkinfo=0
(http://ip/cgi-bin/images_cgi?channel=1&user=admin&pwd=admin)

Learning OpenCL programming

This post is to record the steps how I run my first “Hello World” OpenCL C++ program.

  1. To make things easier, I created this, OpenCL.zip, OpenCL library and C/C++ header files.
  2. Create a Visual Studio C++ project
  3. The following code is to add two 2^25 array altogether using GPU:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#define __CL_ENABLE_EXCEPTIONS
#include <CL\cl.hpp>

// Compute c = a + b.
static const char source[] =
"kernel void add(\n"
"       ulong n,\n"
"       global const float *a,\n"
"       global const float *b,\n"
"       global float *c\n"
"       )\n"
"{\n"
"    size_t i = get_global_id(0);\n"
"    if (i < n) {\n"
"       c[i] = a[i] + b[i];\n"
"    }\n"
"}\n";

int main() {

	const size_t N = 1 << 25;

	try {
		// Get list of OpenCL platforms.
		std::vector platform;
		cl::Platform::get(&platform);

		if (platform.empty()) {
			std::cerr << "OpenCL platforms not found." << std::endl;
			return 1;
		}

		// Get first available GPU device.
		cl::Context context;
		std::vector device;
		for (auto p = platform.begin(); device.empty() && p != platform.end(); p++) {
			std::vector pldev;

			try {
				p->getDevices(CL_DEVICE_TYPE_DEFAULT, &pldev);

				for (auto d = pldev.begin(); device.empty() && d != pldev.end(); d++) {
					if (!d->getInfo()) continue;

					std::string ext = d->getInfo();

					device.push_back(*d);
					context = cl::Context(device);
				}
			}
			catch (...) {
				device.clear();
			}
		}

		if (device.empty()) {
			std::cerr << "GPUs device not found." << std::endl;
			return 1;
		}

		std::cout << device[0].getInfo() << std::endl;

		// Create command queue.
		cl::CommandQueue queue(context, device[0]);

		// Compile OpenCL program for found device.
		cl::Program program(context, cl::Program::Sources(
			1, std::make_pair(source, strlen(source))
			));

		try {
			program.build(device);
		}
		catch (const cl::Error&) {
			std::cerr
				<< "OpenCL compilation error" << std::endl
				<< program.getBuildInfo(device[0])
				<< std::endl;
			return 1;
		}

		cl::Kernel add(program, "add");

		// Prepare input data.
		std::vector a(N, 1);
		std::vector b(N, 2);
		std::vector c(N);

		// Allocate device buffers and transfer input data to device.
		cl::Buffer A(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
			a.size() * sizeof(float), a.data());

		cl::Buffer B(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
			b.size() * sizeof(float), b.data());

		cl::Buffer C(context, CL_MEM_READ_WRITE,
			c.size() * sizeof(float));

		// Set kernel parameters.
		add.setArg(0, static_cast(N));
		add.setArg(1, A);
		add.setArg(2, B);
		add.setArg(3, C);

		// Launch kernel on the compute device.
		queue.enqueueNDRangeKernel(add, cl::NullRange, N, cl::NullRange);

		// Get result back to host.
		queue.enqueueReadBuffer(C, CL_TRUE, 0, c.size() * sizeof(float), c.data());

		// Should get '3' here.
		std::cout << c[42] << std::endl;
	}
	catch (const cl::Error &err) {
		std::cerr
			<< "OpenCL error: "
			<< err.what() << "(" << err.err() << ")"
			<< std::endl;
		return 1;
	}
}

Generate large prime numbers using boost library

Recently I am working on a RSA like algorithm project, which needs to generate large secret prime numbers, e.g. 512 bits, or 1024 bits. Luckily we are using boost library, which is inbuilt lots of functions to assist this generation.

#include <boost/multiprecision/miller_rabin.hpp>
#include <boost/random/mersenne_twister.hpp>

using namespace boost::multiprecision;
using namespace boost::random;

...
//Generate a secret RSA-like 512 bits primes p
cpp_int p = GetPrime();
...
cpp_int GetPrime()
{
    mt11213b base_gen(clock());
    independent_bits_engine<mt11213b, 512, cpp_int> gen(base_gen);

    // Generate some large random primes
    // Note 25 trials of Miller-Rabin 
    // likelihood that number is prime
    cpp_int n;
    do
    {
        n = gen();
    }while (!miller_rabin_test(n, 25));
    return n;
}

FFmpeg is very handy utility to edit multimedia file

FFmpeg is very powerful open source multimedia tool. The source code is hosted at https://github.com/FFmpeg/FFmpeg, and the pre-compiled binary version can be found at https://ffmpeg.zeranoe.com/builds/. However, sometimes, it not user friendly, and you have to remember many parameters.

Here are some samples, which I regular used:

Converting video and audio into different format

$ ffmpeg -i input.mp4 output.avi

Compressing video

$ ffmpeg -i input.mp4 -s 640x360 output.mp4

Changing bitrate

$ ffmpeg.exe -i input.avi -b 3000k  -maxrate 4000k -bufsize 1835k output.avi

Concating video

$ ffmpeg.exe -f concat -i filelist.txt -c copy concat.avi

filelist.txt

file '1.AVI'   
file '2.AVI'   
file '3.AVI'

Remove audio from video file

$ ffmpeg -i input.mp4 -c copy -an output.mp4

Extract audio from video

$ ffmpeg -i input.avi -vn -acodec copy output.aac

Combining audio into video

$ ffmpeg -i video.mp4 -i audio.m4a -c:v copy -c:a copy output.mp4

Cutting the videos based on start and end time

$ ffmpeg -i input.mp4 -ss 00:00:45 -codec copy -t 40 output.mp4

Adding audio into video file on start and time

$ ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c copy -t 40 output.mkv

Adding Poster Image to an Audio File

$ ffmpeg -loop 1 -y -i image.jpg -i audio.mp3 -acodec copy -vcode
c libx264 -shortest ouput.mp4

Download m3u8 url and save as MP4 file

$ ffmpeg -i "http://url/file.m3u8" ouput.mp4

PHP download large file randomly breaks

Last two days, I was trying to make a PHP page to support large file downloading. It’s supposed to be fairly easy because PHP sample code is everywhere.

	
if (file_exists($file) && is_file($file)) 
{
    set_time_limit(0);
    //write HTTP header
    header('Cache-control: private');
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.filesize($file));
    header('Content-Disposition: filename='.basename($file));
    $handle = fopen($file, 'rb');
    while (!feof($handle)) 
    {
        //limited to 256kb/s
        print(fread($handle, 256 * 1024));
        // flush the content to the browser
        flush();
        // sleep one second
        sleep(1);
        if(connection_status() != 0 || connection_aborted()) 
        {
            break;
        }
    }
    fclose($handle);
    exit;
}

However, a small issue causes a big trouble. For unknown reason, HTTP downloading interrupts and breaks randomly, and I couldn’t download the entire file. I checked the PHP code and changed the PHP.ini, but still couldn’t solve the problem. After hours and hours digging, I found this page, https://www.lacisoft.com/blog/2012/01/21/php-download-script-for-big-files/, which magically solves the issue and saves me heaps.

it is :  ob_end_clean();

Here is the final code:

	
if (file_exists($file) && is_file($file)) 
{
    set_time_limit(0);
    //write HTTP header
    header('Cache-control: private');
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.filesize($file));
    header('Content-Disposition: filename='.basename($file));
    //!!!very important!!!
    ob_end_clean();
    $handle = fopen($file, 'rb');
    while (!feof($handle)) 
    {
        //limited to 256kb/s
        print(fread($handle, 256 * 1024));
        // flush the content to the browser
        flush();
        // sleep one second
        sleep(1);
        if(connection_status() != 0 || connection_aborted()) 
        {
            break;
        }
    }
    fclose($handle);
    exit;
}

I read the PHP manual about this function, and guess it could be PHP out buffering overflow or underflow causes the  break issue. If you are facing the similar issue, I hope this can help you as well.

Change IP address & Mask address (C++) Windows

Introduction

This is one way of changing IP address & mask address in C++ using Iphlpapi.h. It’s a simple program, no UI for you, sorry…

  • Use GetAdaptersInfo to get adapters information.
  • Then use GetPerAdapterInfo to get information for every ethernet network card. The information contains IP address.
  • Use DeleteIPAddress remove the old IP address.
  • Use AddIPAddress to add new IP&Mask address.
// ChangeIPAddress("192.168.0.123", "192.168.0.44","255,255,255,0");
bool ChangeIPAddress(char oldIPAddress[], char newIPAddress[], char newMaskAddress[])
{
    DWORD dwRetVal = 0;
    PIP_ADAPTER_INFO pAdapter = NULL;

    ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
    PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
    if (pAdapterInfo == NULL)
    {
        return false;
    }

    if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
    {
        free(pAdapterInfo);
        pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
        if (pAdapterInfo == NULL)
        {
            return false;
        }
    }

    if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
    {
        pAdapter = pAdapterInfo;
        while (pAdapter)
        {
            if (strcmp(oldIPAddress, pAdapter->IpAddressList.IpAddress.String) == 0)
            {
                IPAddr addr = inet_addr(newIPAddress);
                IPMask mask = inet_addr(newMaskAddress);
                ULONG context, instance;

                if (DeleteIPAddress(pAdapter->IpAddressList.Context) != NO_ERROR
                    || AddIPAddress(addr, mask, pAdapter->Index, &context, &instance) != NO_ERROR)
                {
                    return false;
                }
                return true;
            }
            pAdapter = pAdapter->Next;
        }
        return false;
    }
}

Windows change computer name without reboot

Save this as a batch file, and run from command console

set /p newName=Please input the new computer name:

echo Modifying registry keys...

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /d "%newName%" -f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /d "%newName%" -f 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\ComputerName\ComputerName" /v "ComputerName" /d "%newName%" -f 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" /v "ComputerName" /d "%newName%" -f 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName" /v "ComputerName" /d "%newName%" -f 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters" /v "Hostname" /d "%newName%" -f 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters" /v "NV Hostname" /d "%newName%" -f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters" /v "Hostname" /d "%newName%" -f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters" /v "NV Hostname" /d "%newName%" -f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultDomainName" /d "%newName%" -f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "AltDefaultDomainName" /d "%newName%" -f

echo Finish updating registry...

echo Update DNS...
ipconfig /renew
ipconfig /flushdns
ipconfig /registerdns
echo Finish updating DNS...

set computername=%newName%

Windows physical disk image writer in C

My recent project is to write a raw image file into CFast card, and I was looking for a physical disk writer on google. Finally I found this http://m0n0.ch/wall/physdiskwrite.php, but it doesn’t work properly.

  1. GUI is not Englisht
  2. When image size is too big, it doesn’t show the correct size.

Then I decide to make my own physical disk image writer in C.

Be extremely careful to use this tool, incorrect disk number can completely corrupt your disk data! I am not responsible for this.

Download

PhyDiskWrite.zip (4k)

#include <windows.h>

void PrintHelp()
{
    printf("Usage: phydiskwrite [imagefile]\r\n\r\n");
}

HANDLE OpenDisk(int deviceID)
{
    HANDLE hDisk;
    TCHAR diskName[MAX_PATH];
    _stprintf_s(diskName, _T("\\\\.\\PhysicalDrive%d"), deviceID);
    hDisk = CreateFile(diskName, 
        GENERIC_READ | GENERIC_WRITE, 
        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    return hDisk;
}

int PrintDisks()
{
    printf("Searching for physical drives...\r\n\r\n");
    DWORD bytes;
    TCHAR diskName[MAX_PATH];
    HANDLE hDisk;
    int selectedDisk = -1;
    for (int i = 0; i < 255; i++)
    {
        hDisk = OpenDisk(i);
        if (hDisk == INVALID_HANDLE_VALUE)
            continue;
        printf("Information for Device %d\r\n", i);

        DISK_GEOMETRY pdg = { 0 };
        if (!DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &pdg, sizeof(pdg), &bytes, NULL))
        {
            printf("error: Get disk info failed %d\r\n", GetLastError());
            continue;
        }
        ULONGLONG DiskSize = pdg.Cylinders.QuadPart 
            * (ULONG)pdg.TracksPerCylinder 
            * (ULONG)pdg.SectorsPerTrack 
            * (ULONG)pdg.BytesPerSector;
        CloseHandle(hDisk);
        printf("\tByte/Sec %d, Cylinders: %d, Sector/Track %d, Track/Cylinder %d\r\n", 
            pdg.BytesPerSector, pdg.Cylinders, pdg.SectorsPerTrack, pdg.TracksPerCylinder);
        printf("\tDevice:%d, Media Type:%d Disk Size: %.2f (Gb)\r\n\r\n", 
            i, pdg.MediaType, (double)DiskSize / (1024.0f * 1024.0f * 1024.0f));
    }
    printf("Which disk do you want to write?\r\n");
    printf("(Be careful, wrong disk number could corrupt your entire disk!)\r\n");
    scanf("%d", &selectedDisk);
    return selectedDisk;
}

int _tmain(int argc, _TCHAR* argv[])
{   
    if (argc != 2)
    {
        PrintHelp();
        return 0;
    }
    
    int devID = PrintDisks();
    if (devID != -1)
    {
        HANDLE hDisk = OpenDisk(devID);
        BYTE buffer[65536];
        DWORD byteRead, byteWrite, status;
        ULONGLONG totalWrite = 0;
        LARGE_INTEGER fileSize;
        HANDLE hImage = CreateFile(argv[1], 
            GENERIC_READ, FILE_SHARE_READ, NULL, 
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hImage == INVALID_HANDLE_VALUE)
        {
            printf("error: Open file failed %d", GetLastError());
            return -1;
        }

        GetFileSizeEx(hImage, &fileSize);
        while (ReadFile(hImage, buffer, 65536, &byteRead, NULL) && byteRead > 0)
        {
            if (!WriteFile(hDisk, buffer, byteRead, &byteWrite, NULL))
            {
                printf("error: Write to disk failed %d", GetLastError());
                break;
            }
            else
            {
                printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
                totalWrite += byteRead;
                printf("%f%%", totalWrite * 100.0f / fileSize.QuadPart);
            }
        }
        CloseHandle(hImage);
        CloseHandle(hDisk);
    }
    return 0;
}

C# UserControl IPTextBox

I am looking for a TextBox control, which can validate and filter out IP Address. After a bit research, I come with this https://social.msdn.microsoft.com/Forums/vstudio/en-US/4c2aefae-ca6a-4e71-8564-fe73da7107f1/maskedtextbox-formatting-for-an-ip-address?forum=csharpgeneral. It’s easy to implement and simple to use. Just like normal TextBox.

iptextbox

using System.Windows.Forms;
class IPTextBox : TextBox
{
    public IPTextBox() : base()
    {
        SetStyle(ControlStyles.ResizeRedraw, true);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            var cp = base.CreateParams;
            cp.ClassName = "SysIPAddress32";
            return cp;
        }
    }
}

Another complete solution can be found http://www.sanity-free.org/127/an_ipaddress_control_the_win32_sysipaddress32_control_in_csharp.html