How to integrate a Drift camera into your APP


Drift has open APIs to allow users to utilize their product for various customized applications. This document explains how to get a real-time video stream from a Drift camera, and how to remotely control or configure Drift cameras.

An application can access the live video feed from Drift camera through TCP or RTSP protocol. The Drift camera acts as a video streaming server when configured, while the application, run on either a PC or mobile phone, can acquire real-time video stream through TCP or RTSP URLs.

Besides acting as an RTSP/TCP server, Drift cameras can also be configured or commanded to livestream to an RTMP server (either in the cloud or in a local network). 

1. AP MODE

Drift camera works in AP mode (application accesses camera directly)

By default, TCP mode is enabled on Drift cameras, which means once the camera’s Wi-Fi network is turned on it will act as a server providing real time H.264 video through the TCP protocol. The client application can use standard TCP protocol to obtain video frames. Just keep in mind, with this protocol you will get video but no sound. 

1.1 Setting up a Drift Camera as a TCP Server

 Create a text file named “fmcam.conf”, insert the below contents in the file then save it to the root directory of your memory card. Make sure the suffix is conf

stream_type=tcp

Note: once the file “fmcam.conf” is on the memory card, every time when start camera Wi-Fi as AP mode, it will act as a video streaming server through TCP protocol. If you don’t want to use this feature anymore, simply delete the file and camera will resume to normal. 

 

1.2 Test Methodology 

1) Install VLC player on PC.

2) Put the fmcam.conf file into your Drift camera root directory, turn camera on, wait till the Wi-Fi LED becomes solid green and connect PC to the camera’s Wi-Fi network. Your camera’s Wi-Fi network will have a name such as“Ghost ZZ-XXXXX”, depending on the Drift camera model.

 

3) Open VLC on your PC, navigate to media / open network streaming, input below texts: “tcp://192.168.42.1:8001” in the URL dialog , where "192.168.42.1" is the default IP address of your Ghost camera. 

4) Select “Show More Options”, in the dialog of “Edit Options”, add “:demux=h264”.

 

5) Click on “Play” and you should see the live video in your VLC player. 

  

2. STATION MODE

Drift Camera works in “Station” mode -  applications access camera through router

2.1 To set up Drift camera as RTSP server in the local network:

Create a text file named “fmcam.conf”, insert the below contents in the file and specify the value of each line according to your own network. Once done, save the file to the root directory of the camera memory card, and make sure the suffix is conf

 

router_ssid=xxxxxx

router_password=12345678

static_ip=192.168.4.148

static_router=192.168.4.1

static_netmask=255.255.255.0

stream_type=rstp

stream_resolution=720P

stream_bitrate=2000000

stream_framerate=30

Note: 

a) you can configure the stream resolution as 480P, 720P or even 1080P. A stream bitrate 2000000 stands for 2Mbps, and the framerate options are 30 or 60. Here is the recommended setup for each model.

Ghost X: 720P, 2000000, 30    (don’t set higher than this to avoid camera freezing)

Ghost XL: 720P, 2000000,30   (don’t set higher than this to avoid camera freezing)

Ghost 4K+, 1080P, 8000000, 60  (can be up to 4K resolution and 30Mbps bitrate) 

b) once the file “fmcam.conf” is on the memory card, each time you power the drift camera on it will automatically open the Wi-Fi network and act as a video streaming server. If you don’t want to use this feature anymore, simply delete the file and camera will resume to normal. 

 

 2.2 Test Methodology 

1) Install VLC player on PC.

2) Put the fmcam.conf file (described in 2.1) into your camera root directory of memory card, then restart it, the camera will automatically connect to the router, with the appointed IP address. 

3) Open VLC on your PC, navigate to media / open network streaming, input below texts  “rtsp://192.168.4.148/live” in the URL dialog , where "192.168.4.148" is the static IP address you appointed in the configure file. 

4) Click on “Play”, you should see the live video on your VLC player. 

 

3. Remote control 

Remotely Control & Setup Drift a camera 

If you want to develop an application to control or setup a Drift camera in a specific network, please follow these steps.

3.1 Configure the camera into this network with a fmcam.conf file, with the below contents inserted. The purpose of this file is to specify the router name/password and static IP address, you can skip the static_ip setup in the script file, in this case, camera will be dynamic allocated an IP address through DHCP protocol.

router_ssid=xxxxxx

router_password=12345678

static_ip=192.168.4.148

static_router=192.168.4.1

static_netmask=255.255.255.0


Note: 

"static_ip" is set to the static IP address of the camera (please use an address not assigned by the router), "static_router" is the router gateway address, and "static_netmask" is the network subnet mask. Only when all the three parameters "static_ip", "static_router" and "static_netmask" are specified in the script at the same time, the static IP address will be taken effect. If one is missing, the dynamically assigned IP address will be used.

 

3.2 Use the below commands to setup or control your Drift camera. (take the static IP address 192.168.4.148 set above as an example, you can write yours when developing your own application).

If using DHCP to dynamic allocate IP address, you can find the camera’s IP address (last 8 bits) from camera’s rear screen. e.g, if your camera is in the network of 192.168.4.1, and you saw the string on the camera’s LCD: rtsp 10, then your camera’s IP address is 192.168.4.10. 


3.2.1  Operations API


1) Zoom in/out

http://192.168.4.148/cgi-bin/foream_remote_control?dzoom=1

where the value set to dzoom can be from 0 to 10, 0 means no dzoom. 


 2) Start Recording

http://192.168.4.148/cgi-bin/foream_remote_control?start_record

 

3) Stop Recording

http://192.168.4.148/cgi-bin/foream_remote_control?stop_record


4) switch to video mode

http://192.168.4.148/cgi-bin/foream_remote_control?switch_video_mode


5) switch to photo mode

http://192.168.4.148/cgi-bin/foream_remote_control?switch_photo_mode


6) take photo

Before take photo, you need to make sure cam is on photo mode, you can run switch_photo_mode cmd to switch mode.

http://192.168.4.148/cgi-bin/foream_remote_control?take_photo


7)  Reset Setting

http://192.168.4.148/cgi-bin/foream_remote_control?reset_setting 


8) Reboot your Camera

http://192.168.4.148/cgi-bin/foream_remote_control?reboot


9) Power off your camera

http://192.168.4.148/cgi-bin/foream_remote_control?power_off 


10) Setup RTMP live streaming

http://192.168.4.148/cgi-bin/foream_remote_control?start_rtmp_with_param=192.168.3.133:1935/live/5&stream_res=720P&stream_bitrate=2000000

where 192.168.3.133:1935/live/5 stands for the URL of your RTMP server, here rtmp:// is omitted. 

You can also setup the livestream resolution & bitrate with this command. 

Note:in case the RTMP URL contains 【&】 character, please replace it with 【***】.

For example:

If the rtmp url is "rtmp://wxalivepush.weixin.qq.com/live/wx3059da5fb34ccef3-4?txSecret=bc91766cea0589c907c764cdf41d0047&txTime=629f7600"

The URL should be replaced to "rtmp://wxalivepush.weixin.qq.com/live/wx3059da5fb34ccef3-4?txSecret=bc91766cea0589c907c764cdf41d0047***txTime=629f7600"


11) Stop live stream

http://192.168.4.148/cgi-bin/foream_remote_control?stop_rtmp


12) Record with parameters

http://192.168.4.148/cgi-bin/foream_remote_control?record_with_param=PriName&sec_id=SecName

 This API can be used to name the file name generated by video recording. The keywords are PriName and SecName. The keywords only support letters and numbers, so the generated file name is: "Priname_Secname". You can get the customized name from mediaInfo API.


3.2.2  Camera Settings

1)  Setup Camera LED Indicator

 http://192.168.4.148/cgi-bin/foream_remote_control?led=1

where the value: 1 stands for On, 0 stands for Off


2) Setup Camera Exposure Value

 http://192.168.4.148/cgi-bin/foream_remote_control?exposure=1

where the value:  0 stands for 0, 1 stands for 1, 2 stands for 2, 3 stands for -1, 4 stands for -2.

 

3) Set Camera Filter

 http://192.168.4.148/cgi-bin/foream_remote_control?filter=1

where the value: 0 stands for Normal, 1 stands for Vivid and 2 stands for Low Light and 3 for Water.


4) Setup Camera Mic Sensitivity

http://192.168.4.148/cgi-bin/foream_remote_control?mic_sensitivity=1

where the value should be 0 – 4, stands for each Mic level. 


5) Setup camera datetime stamp

http://192.168.4.148/cgi-bin/foream_remote_control?stamp=1

where the value: 0 stands for the closing datetime stamp (watermark), 1 stands for the opening datetime stamp (watermark).

 

6) Setup Camera fov

http://192.168.4.148/cgi-bin/foream_remote_control?fov=140

where the value should be 140,115,90.

 

7) Setup Camera thumbnail file

http://192.168.4.148/cgi-bin/foream_remote_control?thm=1

where the value should be 0 or 1.


8) Setup Camera language

http://192.168.4.148/cgi-bin/foream_remote_control?language=1

where the value: 0 stands for English, 1 stands for Chinese.


9) setup camera time 

http://192.168.4.148/cgi-bin/foream_remote_control?set_time=2021-03-01_09:35:00

setup the camera time to : 2021/3/1 9:35.


3.2.3  LiveStream Settings


1) Setup Livestream Resolution

http://192.168.4.148/cgi-bin/foream_remote_control?stream_res=0

 

where the value of stream_res can be:

Ghost X,Ghost XL,X3: 0 (1080P), 2(720P), 3(WVGA)

Ghost 4K+, 0(4K), 1(4KUHD), 2(27K), 3(1080P), 4(720P),5(WVGA).


Note:camera of Ghost X, X3 and Ghost XL only support to 1080P, while Ghost 4K+ supports 4K.

 

2) Setup Livestream Bitrate

 http://192.168.4.148/cgi-bin/foream_remote_control?stream_bitrate=1000000

 

where stream bitrate value is in Byte, 1000000 means 1Mbyte, 8Mbps.

 

Note:  recommended to use 2.0Mbps for 720P, and 4Mbps for 1080P


3) Setup Livestream Framerate

http://192.168.4.148/cgi-bin/foream_remote_control?stream_framerate=30

where stream_framerate can be 30 for Ghost X, Ghost XL, X3, and up to 240 for GHOST 4K+.


GHOST 4K+ / N1 / N2:

4K(4096 * 2160 17:9):              24 / 25FPS 

4KUHD(3840 * 2160,16:9):       24 / 25 / 30FPS 

2.7K(2704 * 1520,16:9):           24 / 25 / 30 /50 FPS 

1080P(1920 * 1080,16:9):           24 / 25 / 30 / 50 / 60 / 100 / 120FPS 

720P(1280 * 720,16:9):            25 / 30 / 50 / 60FPS 

WVGA(854 * 480,16:9)              25 / 30FPS 



3.2.3  Video Settings

1) Setup Video Resolution

http://192.168.4.148/cgi-bin/foream_remote_control?video_res=0


where the value of video_res can be:

Ghost X,Ghost XL,X3: 0 (1080P), 2(720P), 3(WVGA)

Ghost 4K+, 0(4K), 1(4KUHD), 2(27K), 3(1080P), 4(720P),5(WVGA).

  

2) Setup Video Bitrate

 http://192.168.4.148/cgi-bin/foream_remote_control?video_bitrate=1000000

 

where video bitrate value is in Byte, 1000000 means 1Mbyte, 8Mbps. 

 

 3) Setup Video Framerate

http://192.168.4.148/cgi-bin/foream_remote_control?video_framerate=30

 

where video_framerate can be 30 for Ghost X, Ghost XL, X3, and up to 240 for GHOST 4K+.

GHOST 4K+ / N1 / N2:

4K(4096 * 2160 17:9):              24 / 25FPS 

4KUHD(3840 * 2160,16:9):       24 / 25 / 30FPS 

2.7K(2704 * 1520,16:9):           24 / 25 / 30 /50 FPS 

1080P(1920 * 1080,16:9):           24 / 25 / 30 / 50 / 60 / 100 / 120FPS 

720P(1280 * 720,16:9):            25 / 30 / 50 / 60FPS 

WVGA(854 * 480,16:9)              25 / 30FPS 


 3.2.4 Camera Status

1) get camera current status (only support X3, GHOST 4K+, GHOST XL Pro, N1 and N2)

http://192.168.4.148/cgi-bin/foream_remote_control?get_camera_status

return camera status in XML, for example:

<?xml version="1.0" encoding="utf-8"?>

<Response>

<Status>1</Status>

<Cam_Status>

<camera_status>

<capture_mode>0</capture_mode>

<battery>1</battery>

<sd_free>31150080</sd_free>

<sd_total>31154688</sd_total>

<rec_time>0</rec_time>

<fw_ver>8022</fw_ver>

<model_name>N1</model_name>

</camera_status>

<video_setting>

<res>2</res>

<framerate>30</framerate>

<bitrate>2000000</bitrate>

<quality>2</quality>

</video_setting>

<stream_setting>

<stream_res>2</stream_res>

<stream_framerate>30</stream_framerate>

<stream_bitrate>2000000</stream_bitrate>

</stream_setting>

<camera_setting>

<dzoom>0</dzoom>

<filter>0</filter>

<exposure>0</exposure>

<mic>3</mic>

<led>1</led>

<hd_record>0</hd_record>

</camera_setting>

</Cam_Status>

</Response>

Where the item :

<capture_mode>: 0 stands for video mode , 1 stands for photo mode, 2 stands for timelapse mode, 3 stands for burst mode;

N1/N2 only support video and photo mode.

<battery> means the remaining battery in percentage

<sd_free> means the free size of TF card capacity in KB, if the free size is less than 400Mbps, it will prompt card full and the recording is not allowed.

<sd_total> means the total size of TF card capacity in KB.

<rec_time>: 0 means camera is in idle mode, otherwise it stands for current recording time.

<fw_ver> the FW verson.

<model_name> the model name of camera

<hd_record>: 0 means it’s now in live streaming mode, 1 means it's now in HD recording mode.


 3.2.5 Camera file operations

1) list SD media folders

http://192.168.4.148/cgi-bin/foream_remote_control?list_folders=/tmp/SD0/DCIM

list all the media folders (DCIM) in the camera SD card


<?xml version="1.0" encoding="utf-8"?>

<Response>

<Folders>

{"Path":"100MEDIA"},

{"Path":"101MEDIA"},

{"Path":"102MEDIA"},

</Folders>

<Amount>3</Amount>

</Response>


2) list SD media files

http://192.168.4.148/cgi-bin/foream_remote_control?list_files=/tmp/SD0/DCIM

list all the media files on SD card.

<?xml version="1.0" encoding="utf-8"?>

<Response>

<Files>

{"Path":"100MEDIA/VID00001.MP4","CreateTime":"Nov 03 11:38:00 2021","Size":112767067,"Thumb":0},

{"Path":"100MEDIA/VID00002.MP4","CreateTime":"Nov 03 13:32:08 2021","Size":1686118,"Thumb":0},

{"Path":"100MEDIA/VID00003.MP4","CreateTime":"Nov 03 13:35:52 2021","Size":146324100,"Thumb":0}, 

</Files> 

<Amount>3</Amount>

</Response>

Note:

If you want to preview or download the media file, please use the following URL:

http://192.168.4.148/DCIM/100MEDIA/VID00001.MP4

http://192.168.4.148/DCIM/100MEDIA/VID00002.MP4


3) list customized name video files

http://192.168.4.148/cgi-bin/foream_remote_control?mediaInfo

list all the video files witch was customized file name on SD card.

<?xml version="1.0" encoding="utf-8"?><Response><Status>1</Status><Files>

{

"files": [{

"path": "DCIM\\100MEDIA\\VID00001.MP4",

"name": "priname_name123",

"time": "2022-09-12 14:22:40",

"size": "86620487"

},

{

"path": "DCIM\\100MEDIA\\VID00002.MP4",

"name": "priname_name456",

"time": "2022-09-12 15:22:40",

"size": "85420487"

}]

}</Files></Response>

 

4) delete SD media files

http://192.168.5.56/cgi-bin/foream_remote_control?delete_media_file=100MEDIA/VID00003.MP4

Note: can't call this API if the camera is recording....

 

5) delete multiple SD media files

http://192.168.5.56/cgi-bin/foream_remote_control?delete_media_multfiles=3|100MEDIA/VID00003.MP4|100MEDIA/VID00004.MP4|100MEDIA/VID00005.MP4

The separator character "|" is used between files. The first item must specify the number of files. The number of files must not be greater than 40, can't call this API if the camera is recording....

Note:For iOS app, need to replace the 【|】 character with 【*%7C*】, for example:

http://192.168.5.56/cgi-bin/foream_remote_control?delete_media_multfiles=3*%7C*100MEDIA/VID00003.MP4*%7C*100MEDIA/VID00004.MP4*%7C*100MEDIA/VID00005.MP4


4. How to automatically detect and control a Drift camera in the network

   

Drift has designed an easy and intuitive solution to establish connection between camera and application when they are in the same network. The workflow is as follows: Application creates a QR code with router’s SSID/Password contained, Drift camera scans the QR code to get the info then it will automatically connect (to the router). Then, the Drift camera will broadcast a UDP package to present itself to devices (mobile or PC) in the same network. The package contains the necessary info for the device to establish the connection. Once connected, the device can issue http command to Drift camera for further actions, the following are the details of how the connection can be established. 

 

 4.1 QR code format

 

The format of the QR code is:

17|router_ssid|router_password|stream_type

 

Definition:

1)17 - fixed value to specify the type of QR code, 

2)router_SSID – Wi-Fi name, can’t be empty

3)router_Password – Wi-Fi password, can be empty

4)stream_Type - stream type, either TCP, or RTSP.

 

    Any official QR code tool (e.g. https://www.qr-code-generator.com/) can generate the required code with the text. To develop your own app, you can take the below open source as reference.

ZXing ("Zebra Crossing" barcode scanning library for Java, Android). 

https://github.com/zxing/zxing

 

4.2. Broadcast package (UDP) format

 

The broadcast package (from camera) is in this format

5|cam_serial|cam_model|cam_status

 

Definition:

1)5 - fixed value to specify the broadcast type

2)cam_Serial – Camera Serial Number

3)cam_Model – Camera Model

4)cam_Status - Camera Status, the default is n, indicating normal status.

 

Note: camera’s IP address is embedded in the header of the UDP message which can be extracted. 

 

4.3. Acquire real-time video feed from camera

once the connection is established, an application can use a media player (such as VLC, ijk or vitamio player) to acquire real-time video feed. The command format is the following

RTSP:

rtsp://Camera IP/live

TCP:

tcp://Camera IP:8001

 

4.4. Camera control

Once the connection is established, the application can manipulate camera with the commands described in section 3.2. 

  

5. List of Commands used in script file

   

You can configure your Drift camera with a script file, file name must be “fmcam.conf’, the following is the command list.

 

router_ssid=xxxxxx                                            //specify the router name 

router_password=12345678                              //specify router’s password

static_ip=192.168.4.148

static_router=192.168.4.1

static_netmask=255.255.255.1

 

stream_type=rstp                                                //value can be rtsp or tcp

stream_resolution=720P                                    // value can be 480P, 720P, 1080P, 27K, 4KUHD, 4K

stream_bitrate=2000000                                    // 2000000 stands for 2Mbps

stream_framerate=30

 

custom_stamp=XXXXXXX    //Maximum 7 characters, characters can be shown as watermark 

microphone=1                        // 1: forced to external Mic, 0: force to internal Mic

 

usb_asix = 1                            //forced to external Ethernet module (only for Ghost 4K+)

usb_wifi = 1                             //forced to external Wi-Fi module (only for Ghost 4K+)

 

rtmp_url=rtmp://…                 //specify livestream URL.


附件
文档更新时间: 2023-07-31 21:44   作者:foreamdoc