#### Skywatch Innovation Inc.
##### Company Confidential
Skywatch Merge CR
===
###### tags: `API Documents` `common`
---
# API
Create Merge CR
---
#### Description
隨選錄影
根據客⼾端需求開始時間及結束時間,可獲得指定時間 約 20:1 的比例快轉。伺服器會將此任務加入⼯作序列中,並可透過 mergeCRList API 得知每項任務的處理狀態。
- 每個檔案建議時間設定為原始 150 分鐘內,若 CR 檔案已完成則可於 post 後約 5-15 分鐘內可取得
- 每個檔案建議最高在 8小時內 (2GB以下)
- 該帳號每天檔案上限為快轉 60 分鐘 per 攝影機
- 假設帳號裡有 100 台攝影機,每天檔案上限為快轉 6000 分鐘
- 開始時間:早於結束時間, 不需為過去時間
- 結束時間:晚於開始時間, 不需為過去時間
Generating recording files on demand
Based on start time and end time to download a recording file with 20 times speed of Smart FastForward. Customer can verify the result from megeCRList API after the request is submitted.
- The longest period is 8 hours (< 2GB)
- start_time:earlier than start_time
- end_time:later than start_time
#### Usage
```bash
curl -L -s --verbose -X "POST" \
"https://service.skywatch24.com/api/v2/devices/{device_id}/mergeCR" \
-H 'Content-Type:application/x-www-form-urlencoded;' \
--data-urlencode "api_key={api_key}" \
--data-urlencode "start_time={start_time}" \
--data-urlencode "end_time={end_time}"
```
#### Example Output:
```
{ "result":"1", "data":{"merge_id":"25"}}
```
#### Note
```
start_time & end_time 需使用 unix timestamp,可參考
--data-urlencode "start_time=1604889827" \
--data-urlencode "end_time=1604889830"
```
Get Merge CR Task List
---
#### Description
取得此攝影機底下所有 merge CR 任務編號及任務狀態
任務狀態分為: pending, processing, done 三種
pending: 伺服器尚未處理任務
proceessing: 伺服器正在處理任務
done: 伺服器已完成任務
suspend: Merge CR 指定的時間區間內, 沒有產生任何的 CR 檔案或 CR 檔案太破碎, 之後呼叫該 merge_id 的 get mergeCR API ,只會拿到空字串
Retrieve a list of tasks of merge CR of the camera.
Status of a task
pending: the task is waiting for processing
processing: the task is in progress
done: the task has been completed.
#### Usage
```bash
curl -L -s --verbose -X GET \
-H 'Content-Type: application/x-www-form-urlencoded' \
'https://service.skywatch24.com/api/v2/devices/{device_id}/
mergeCRList?api_key={api_key}'
```
#### Example Output
```bash
[{ id: "1", user_id: "6995", device_id: "1", start_time: "1588586300",
end_time: "1588586900", status: "done", settings: { from: false, mac: "F84DFC69ADC1"}}, { id: "2", user_id: "6995", device_id: "1", start_time: "1588586400", end_time: "1588586900", status: "processing",
settings: { from: false, mac: "F84DFC69ADC1"}}]
```
Get Each MergeCR Task Url
---
#### Description
指定一任務編號, 根據任務處理的狀況, 回傳不同的 URL
[狀況一]: 指定時間區間的 CR 尚未錄製完成
回傳 指定開始時間的 串流 URL 連結
使用 Get Tasks 取得任務 pending 狀態
使用範例
目前時間: 15:08
欲取得錄影時間為: 15:00 – 15:05
使用者可以取得 mp4 串流 url 連結開始,進行 15:00 的影像串流播放
[狀況二]: 指定時間區間的 CR 檔案已部分錄製完成, 但尚未擷取完成
回傳 指定開始時間的 CR 10 分鐘檔案 下載 URL 連結
使用 Get Tasks 取得任務 取得任務 pending 狀態
使用範例
目前時間: 15:15
欲取得錄影時間為: 15:00 – 15:05, CR 檔案產生時間為 0, 10, 20, 30, 40, 50 分
使用者可以取得 15:00 - 15:10 的 CR 檔案下載 URL 連結
[狀況三]: merge CR 任務已經完成
回傳 使用者指定時間區間之錄影檔案 下載 URL 連結
使用 Get Tasks 取得任務 取得任務 done 狀態
使用範例
目前時間: 17:21
欲取得錄影時間為: 15:00 – 15:10
使用者可以取得 15:00-15:10 檔案下載 URL。
Retrieve the URL of the task of Merge CR. The URL will vary with the status of the task.
[Pending]: Return the URL of streaming at the start time for viewing.
[Processing]: Return the URL of the file of the first 10 minutes in the assigned period for downloading.
[Done]: Returen the URL of the file of the assigned period for downloading.
#### Usage
```bash
curl -L -s --verbose -X GET \
-H 'Content-Type: application/x-www-form-urlencoded' \
'https://service.skywatch24.com/api/v2/devices/{device_id}/
mergeCR?api_key={api_key}&merge_id={file_id}'
```
#### Example Output
```
[case1] if file is ready -> download merged file link
https://s3-ap-northeast-1.amazonaws.com/shared-sandbox-storage-s3-ap-northeast-1.amazonaws.com/merge_cr/6995_1_24.mp4?xxxxxxx
[case2] if file not ready & all CR files is ready -> download first CR file link
https://s3-ap-northeast-1.amazonaws.com/shared-sandbox-storage-s3-ap-northeast-1.amazonaws.com/6995/1/141-1588807537.mp4?xxxxxxx
[case3] if file not ready & not all CR files is ready -> cache file link http://tw.be62.skywatch24.com:8888/backend_service/get_now_recording_file.php?xxxx
[case4] if file is not recorded
There is no recording file for now (request for future recording files)
```
# Copyright
> **SKYWATCH CONFIDENTIAL**
Skywatch Innovation Incorporated
All Rights Reserved. support@skywatch24.com
> NOTICE: All information contained herein is, and remains the property of Skywatch Innovation Incorporated and its suppliers, if any. The intellectual and technical concepts contained herein are proprietary to Skywatch Innovation Incorporated and its suppliers and may be covered by Taiwan and Foreign Patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Skywatch Innovation Incorporated.