NAS

synology 透過web api讀取SurveillanceStation攝影機畫面

SurveillanceStation有提供RTSP的方式來讓你可以讀取畫面,但是如果我想要把畫面傳輸到我的網頁上面去的話,就會面臨一個問題,chrome等瀏覽器原生不支援rtsp

這時候解決方是有幾種

  • 寫一個ffmpeg去轉換(頗號資源)
  • 透過VLC開啟串流成m3u8 flv等格式(server那邊vlc就要一直開著)
  • 讓使用者安裝vlc的chrome外掛
  • 透過下列方式直接從nas抓取mpeg格式的串流

你可以透過先拿版本列表(注意下面IP跟port要改成你synology的

http://192.168.2.100:5000/webapi/entry.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth,SYNO.FileStation.

然後他應該會回傳

{"data":{"SYNO.API.Auth":{"maxVersion":7,"minVersion":1,"path":"entry.cgi"},"SYNO.FileStation.BackgroundTask":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.CheckExist":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.CheckPermission":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Compress":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.CopyMove":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.CreateFolder":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Delete":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.DirSize":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Download":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.External.GoogleDrive":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Extract":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Favorite":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.FormUpload":{"maxVersion":2,"minVersion":2,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Info":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.List":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.MD5":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Mount":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Mount.List":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Notify":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.PhotoUpload":{"maxVersion":3,"minVersion":2,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Property":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Property.ACLOwner":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Property.CompressSize":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Property.Mtime":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Rename":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Search":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Search.History":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Settings":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Sharing":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Sharing.Download":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Snapshot":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Thumb":{"maxVersion":3,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Timeout":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.UIString":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.Upload":{"maxVersion":3,"minVersion":2,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.UserGrp":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.Connection":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.File":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.GDrive":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.Profile":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.Protocol":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VFS.User":{"maxVersion":1,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"},"SYNO.FileStation.VirtualFolder":{"maxVersion":2,"minVersion":1,"path":"entry.cgi","requestFormat":"JSON"}},"success":true}

接下來要來透過web get方式驗證登入,其中裡面有個version 記得在上面的最高跟最低版本內即可

然後把你的帳密修改上去

http://192.168.2.100:5000/webapi/entry.cgi?api=SYNO.API.Auth&version=6&method=login&account=帳號&passwd=密碼

送出後會得到下列資訊,其中的sid是我們要的資訊

{"data":{
"did":"HRM65t7zWNYd-xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"is_portal_port":false,
"sid":"xxxxx-k-xxxxxxxxxxxxxxxxxxxxxxxx"
}
,"success":true}

到目前為止,你已經拿到我們需要的SID了

這時候你還欠缺兩個東西,第一個是攝影機的ID,另一個是該攝影機的stmkey

所以我們需要回到我們的synology SurveillanceStation去找到你想要讀取的哪台攝影機

右鍵選擇分享串流路徑,這時候就會看到下圖

在圖上面可以找到兩個資訊,一個就是攝影機ID 如圖是2 另一個就是stmkey 有點長一串

之後我們就可以透過下面方式來開啟攝影機了

http://192.168.2.100:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=9&_sid="______你的SID資訊______"&StmKey=____攝影機分享的key

你要把你的攝影機ID更改上去上面的cameraId 然後把你SID資訊跟StmKey都貼上去 這樣就可以了

你可以直接用img方式直接開啟即可

<img style="display: block;-webkit-user-select: none;" src="http://192.168.2.100:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=9&_sid="xx-k-xxx"&StmKey=b984axxxxxxxx621">

參考文章:DSM Login Web API Guide – Synology

SurveillanceStation web api

Be the First to comment.

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

(若看不到驗證碼,請重新整理網頁。)