LoginSignup
5
0

More than 5 years have passed since last update.

Build & de:code 2018 でも発表された Video Indexer のアップデート

Posted at

streampack の Tana です。

先日の de:code 2018 に参加して MS のビジョン、新製品の発表、交流で色々刺激を受け勉強させていただきました。その中で streampack では Media 関連のサービスにもキャッチアップしておりますので、今回は アップデートされた Video Indexer について試したので共有させていただきます。

Video Indexer とは?

Video Indexer とは、Cognitive Services の一つになります。動画を分析し音声から字幕用のテキストにしたり、動画からフレームごとのOCR抽出、顔検出など様々な分析を一度にやってくれる便利なものです。これができることによって、動画内のメタ検索だったり、特定シーンの検出が可能になります。Video Indexer は API も提供されており、新しく V2バージョン の API が発表になりました。 V1 は残念ながら今年の8月で Duplicated になりますので、V1を使っている人は移行が必要です。

また、以前は Trial バージョンでしたが、 Previewバージョンが出て料金も発表されております。
https://azure.microsoft.com/en-us/pricing/details/cognitive-services/video-indexer/

Region: Japan East で見る限りでは Video分析は input ファイルの1分あたり ¥7.46 のようです。 Audioのみの分析は ¥1.80 となっております。

API V1 と V2 の違い

V1 では、token をセットして Video Indexer V1 の API を投げれば、アップロードしたり、分析したり、動画リスト抽出が簡単でしたが、V2 では user, account, video ごとに token を取得する必要があり少し複雑になっております。 token も1時間で切れますので、必要に応じて再取得が必要です。

API にて動画リストを取得するまでのフロー

基本こちらのフローになりますが、 authorization scope という定義があり、少々理解し難いものです。
https://docs.microsoft.com/en-us/azure/cognitive-services/video-indexer/video-indexer-use-apis

今回は試しに List Videos の取得の場合に、必要なフローを要約します。
https://api-portal.videoindexer.ai/docs/services/operations/operations/List-videos?

これで必要なのは、

  • location
  • accountId
  • accessToken(An account access token with read permissions)

APIページ見ても結構情報が多くて混乱しますが、 List Video API で必要な accessToken は account 用のトークンです。 Video, User トークンではなくSubscription key でもないので要注意です。

すでに、Video Indexer に Sign up 済みという前提で進めます。

1. 動画アップロード

Video_Indexer_-_Cognitive_Video_Indexing.png

上記の Upload から動画をアップロードしておきます。

2. APIのサブスクリプション

下記のページにて、登録します。
https://api-portal.videoindexer.ai/products/authorization

登録完了すると、primary と secondary keys の Subscription Key が取得できます。これをメモしておきます。

3. AccountIDの取得

色々な API をコールするには AccountID が必須です。
下記のページから AccountID を取得します。
https://api-portal.videoindexer.ai/docs/services/authorization/operations/Get-Accounts/console

Query Parameters に下記をセットします。

  • location: trial

Headers の Ocp-Apim-Subscription-Key は自動で先ほど登録した Subscription key を API Console 側でセットしてくれます。

[{
  "id": "xxxxx-91ae-4831-b0bb-xxxxxxxxxxx",
  "name": "xxxxx-xx89xx",
  "location": "Trial",
  "accountType": "Trial",
  "url": "https://www.videoindexer.ai/",
  "accessToken": null
}]

4. Accounts のアクセストークンを取得

ここでは、Query Parameter に location と 先ほど取得した accountID をセットして
コールします。うまく行けば下記のようにテキストの "account token" が返ってきます。

Pragma: no-cache
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
Cache-Control: no-cache
Date: Fri, 25 May 2018 04:38:33 GMT
X-Powered-By: ASP.NET
Content-Length: 423
Content-Type: application/json; charset=utf-8
Expires: -1

"account token"

5. 動画リスト取得

https://api-portal.videoindexer.ai/docs/services/operations/operations/List-videos?

動画の取得は

  • location: trial
  • accountId: xxxxx-91ae-4831-b0bb-xxxxxxxxxxx
  • accessToken: accesstoken <- 4番で取得したtoken
{
  "results": [{
    "accountId": "xxxxx-91ae-4831-b0bb-xxxxxxxxxxx",
    "id": "xxxxxx",
    "partition": null,
    "externalId": "2101axxxxx",
    "metadata": null,
    "name": "Demo動画",
    "description": null,
    "created": "2017-08-23T06:49:17.587+00:00",
    "lastModified": "2018-03-08T05:17:09.801+00:00",
    "lastIndexed": "2018-03-08T05:17:09.801+00:00",
    "privacyMode": "Public",
    "userName": "Tana",
    "isOwned": true,
    "isBase": true,
    "state": "Processed",
    "processingProgress": "",
    "durationInSeconds": 85,
    "thumbnailVideoId": "4877a7xxxx",
    "thumbnailId": "0b6866ef-0532-4e6b-b06a-xxxxxxxxxx",
    "searchMatches": [],
    "indexingPreset": "Default",
    "streamingPreset": "Default",
    "sourceLanguage": "ja-JP"
  }, {

これで一通り取得まで行けました。
あとはこれで、Get-Video-Index にて分析結果を取得したり、
https://api-portal.videoindexer.ai/docs/services/operations/operations/Get-Video-Index?
アップロード API を使ってアップロードできれば、組み込みはスムーズには行けるかと思います。

V1 と違って Brand や Language Model などの新しいものができてますので、その辺りも理解を深める必要があるかもしれません。

結論

ビデオ分析を自前でやろうとすると、Machine Learningの知識・経験、ハイスペックな環境、組み込みなどかなり労力が必要になりますが、たかが API されど API で諸々やってくれるので、試してみる価値はあるかと思います。

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0