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).
- 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.
- 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 the camera Wi-Fi network is opened in 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 revert to normal.
1.2 Test Methodology
- Install VLC player on PC.
- 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.
- Open VLC on your PC, navigate to media, open network streaming and input the below text: “tcp://192.168.42.1:8001” in the URL dialog, and "192.168.42.1" as the default IP address of your Ghost camera.
Select “Show More Options”. In the dialog of “Edit Options”, add “:demux=h264”.
- Click on “Play” and you should see the live video in your VLC player.
- STATION MODE
Drift Camera works in “Station” mode - applications access camera through router
- 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=rtsp
stream_resolution=720P
stream_bitrate=2000000
stream_framerate=30
Note:
- 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)
- 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 revert to normal.
2.2 Test Methodology
- Install VLC player on PC.
- 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.
- Open VLC on your PC, navigate to media / open network streaming, input below text: “rtsp://192.168.4.148/live” in the URL dialog, where "192.168.4.148" is the static IP address you appointed in the configuration file.
- Click on “Play”, and you should see the live video on your VLC player.
- 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.
- 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 and the camera will be dynamically 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
- 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 your own when developing your own application.
If using DHCP to dynamically 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 see the string on the camera’s LCD: rtsp 10, then your camera’s IP address is 192.168.4.10.
- Zoom in/out
http://192.168.4.148/cgi-bin/foream_remote_control?dzoom=1
where the value set to dzoom can be from 1 to 10.
- Setup RTMP live streaming
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 【***】.
- Stop live stream
http://192.168.4.148/cgi-bin/foream_remote_control?stop_rtmp
- 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 720P, while Ghost 4K+ supports 1080P
- 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
- 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 30 or 60 for Ghost 4K+.
- Start Recording
http://192.168.4.148/cgi-bin/foream_remote_control?start_record
- Stop Recording
http://192.168.4.148/cgi-bin/foream_remote_control?stop_record
- Reboot your Camera
http://192.168.4.148/cgi-bin/foream_remote_control?reboot
- Power off your camera
http://192.168.4.148/cgi-bin/foream_remote_control?power_off
- 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
- 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.
- 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, 2 stands for Low Light, 3 stands for water.
- 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.
- Get Camera's Current settings
http://192.168.4.148/cgi-bin/foream_remote_control?get_camera_setting
return camera setting in XML, for example:
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Status>1</Status>
<Setting>
<stream_res>720P</stream_res>
<stream_bitrate>2000000</stream_bitrate>
<dzoom>0</dzoom>
<filter>1</filter>
<exposure>1</exposure>
<mic>3</mic>
<led>1</led>
</Setting>
</Response>
- Get Camera's Current Status
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>
<mode>0</mode>
<battary>90</battary>
<sd>100</sd>
<rec_time>1</rec_time>
<ver>9001</ver>
</Cam_Status>
</Response>
Where the item :
<mode>: 0 stands for video mode , 1 stands for photo mode, 2 stands for timelapse mode, 3 stands for burst mode;
<battery> means the remaining battery in percentage
<sd> means the remaining TF card capacity in percentage
<rec_time>: 0 means camera is in idle mode, otherwise it stands for current recording time.
<ver> the FW verson.
- 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.
- 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 the 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.
- 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
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.