1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

このノートブックの後編では、Amazon Nova を使用した動画処理の実装方法と制限事項について説明します。Nova の動画理解機能は強力ですが、いくつかの重要な制限があることに注意が必要です。

動画処理の基本実装

まず、基本的な動画処理の実装方法を見ていきます。

import base64
import boto3
import json

# Bedrockクライアントの初期化
client = boto3.client(
    "bedrock-runtime",
    region_name="us-east-1",
    aws_access_key_id="YOUR_ACCESS_KEY_ID",
    aws_secret_access_key="YOUR_SECRET_ACCESS_KEY"
)

MODEL_ID = "us.amazon.nova-lite-v1:0"

ローカルビデオの処理

ローカルに保存された動画を処理する例です。

# 動画ファイルの読み込みとエンコード
with open("sample_video.mp4", "rb") as video_file:
    binary_data = video_file.read()
    base64_string = base64.b64encode(binary_data).decode("utf-8")

# システムプロンプトの設定
system_list = [
    {
        "text": "You are an expert media analyst. When the user provides you with a video, provide 3 potential video titles"
    }
]

# ユーザーメッセージの設定
message_list = [
    {
        "role": "user",
        "content": [
            {
                "video": {
                    "format": "mp4",
                    "source": {"bytes": base64_string},
                }
            },
            {
                "text": "Provide video titles for this clip."
            },
        ],
    }
]

# 推論パラメータの設定
inf_params = {
    "max_new_tokens": 300,
    "top_p": 0.1,
    "top_k": 20,
    "temperature": 0.3
}

S3からの動画処理

S3バケットに保存された動画を処理する例です。

# S3からの動画処理用メッセージ
message_list = [
    {
        "role": "user",
        "content": [
            {
                "video": {
                    "format": "mp4",
                    "source": {
                        "s3Location": {
                            "uri": "s3://my_bucket/video1.mp4",
                            "bucketOwner": "123456xxxx"
                        }
                    }
                }
            },
            {
                "text": "Provide video titles for this clip."
            }
        ]
    }
]

動画処理の実行

# リクエストの構築と実行
native_request = {
    "schemaVersion": "messages-v1",
    "messages": message_list,
    "system": system_list,
    "inferenceConfig": inf_params,
}

try:
    response = client.invoke_model(
        modelId=MODEL_ID,
        body=json.dumps(native_request)
    )
    model_response = json.loads(response["body"].read())
    
    print("[Full Response]")
    print(json.dumps(model_response, indent=2))
    
    content_text = model_response["output"]["message"]["content"][0]["text"]
    print("\n[Response Content Text]")
    print(content_text)

except Exception as e:
    print(f"Error occurred: {str(e)}")

重要な制限事項

Nova の動画処理には以下の重要な制限があります:

基本的な制限

  1. 1リクエストにつき1動画: 現在、1回のリクエストで処理できる動画は1つのみです
  2. 音声非対応: 現在のモデルは視覚情報のみを処理し、音声の分析はできません
  3. タイムスタンプ非対応: タイムスタンプ情報の処理や理解はできません

機能の制限

  1. 時間的因果関係: 動画内のイベントの因果関係の理解は限定的です
  2. 手書き文字の理解: 手書き文字の認識は限定的で、誤認識の可能性があります
  3. 多言語対応: 画像や動画フレーム内の多言語テキストの理解は限定的です

セキュリティと特殊ケース

  1. 人物識別: 画像、文書、動画内の個人の識別や命名はサポートしていません
  2. 空間認識: 空間的な推論能力は限定的です
  3. 小さいテキスト: 画像や動画内の小さいテキストは認識が困難な場合があります

その他の制限

  1. カウント機能: オブジェクトの正確な数の計測は難しい場合があります
  2. 不適切なコンテンツ: 利用規約に違反するコンテンツは処理しません
  3. 医療用途: 医療画像や動画の分析は推奨されません

ベストプラクティス

  1. 動画の前処理:

    • 動画の解像度とサイズを適切に調整
    • 重要な部分が明確に見えるようにトリミング
    • テキストが含まれる場合は、十分な大きさを確保
  2. プロンプトの工夫:

    • 具体的な指示を提供
    • 複雑なタスクは小さく分割
    • モデルの制限を考慮したタスク設計
  3. エラーハンドリング:

    • タイムアウトの考慮
    • 適切なエラー処理の実装
    • リトライロジックの実装

トラブルシューティング

エラーが発生した場合は、以下を確認してください:

  • 動画のフォーマットとサイズが適切か
  • S3のアクセス権限が正しく設定されているか
  • リクエストの制限を超えていないか
  • プロンプトが制限事項に触れていないか

📒ノートブック

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?