> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-feature-automate-reference-docs-generation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Video

Weave は自動的に [`moviepy`](https://zulko.github.io/moviepy/)を使用してビデオをログに記録します。これにより、トレース関数にビデオの入力と出力を渡すことができ、Weave はビデオデータのアップロードと保存を自動的に処理します。

<Note>
  ビデオサポートは現在、Pythonでのみ利用可能です。
</Note>

## 使用の前提条件

1. インストール `weave` と `moviepy==1.0.3`。
2. W\&B アカウントを作成します。

## サポートされているビデオタイプ

Weave は `moviepy` ビデオクリップオブジェクトを認識します、例えば：

* ビデオファイルから読み込まれた `VideoFileClip`
* メモリ内クリップ（ `ImageClip`、 `ColorClip`、および `TextClip`

### ファイルベースのクリップの直接アップロード

クリップが `VideoFileClip` で、サポートされている拡張子を持つ有効なファイル名がある場合、Weave はファイルを直接アップロードします。

**サポートされているファイル拡張子：**

* `.mp4`
* `.webm`
* `.gif`

### メモリ内クリップのサポート

ビデオオブジェクトがメモリ内にある場合（ディスク上にファイルがない場合）、Weave はそれを `.mp4` ファイルとしてエンコードし、アップロードを自動的に処理します。これは以下のタイプのクリップに適用されます：

* `ImageClip`
* `ColorClip`
* `TextClip`

## Example: Trace a video function

以下のコードサンプルは、Weave でビデオ処理関数をトレースする方法を示しています。このコードサンプルは：

1. Weave プロジェクトを初期化します `video-test`。
2. `get_video` 関数を `weave.op` としてトラッキングし、読み込まれた `VideoFileClip` から1秒のサブクリップを `VideoClip` として抽出します。
3. クリップをアップロードし、Weave でトラッキングします。
4. MP4ビデオが見つからない場合、自動的にダミーのMP4ビデオを生成します。

<Warning>
  スレッドセーフティの問題を避けるため、常に `VideoFileClip` オブジェクトへのパスを渡し、Weave `op` の外部で作成しないでください。
</Warning>

以下のコードスニペットを使用する前に、[使用の前提条件](#usage-prerequisites)を完了してください。

```python
import os
import weave
from moviepy.editor import VideoFileClip, ColorClip, VideoClip

# Update to your project name, or create a new project named 'video-test'
weave.init('video-test')

@weave.op
def get_video(clip: VideoFileClip) -> VideoClip:
    """Process a video by path rather than by passing the clip directly.

    This ensures that the VideoFileClip is created and managed within the
    Weave op's thread context, avoiding thread-safety issues.
    """
    new_clip = clip.subclip(0, 1)
    return new_clip

if __name__ == "__main__":
    os.makedirs("videos", exist_ok=True)

    # Update the path to point to your MP4 file
    video_path = './videos/example.mp4'

    # Generate a dummy video if it doesn't exist
    # Dummy video contents: A red square that displays for 5 seconds
    if not os.path.isfile(video_path):
        print("No video found. Creating dummy video...")
        dummy_clip = ColorClip(size=(640, 480), color=(255, 0, 0), duration=5)
        dummy_clip.write_videofile(video_path, fps=24)

    clip = VideoFileClip(video_path, has_mask=False, audio=True)
    get_video(clip) 
```

コードサンプルが正常に実行されると、プロジェクトの **Traces** テーブルのリンクをクリックしてビデオを表示できます。

![A trace of a video processing function in the Traces table.](https://mintlify.s3.us-west-1.amazonaws.com/wb-21fd5541-feature-automate-reference-docs-generation/ja/guides/tracking/imgs/video-trace.png)

![An MP4 video uploaded to Weave, viewed in the Traces popout.](https://mintlify.s3.us-west-1.amazonaws.com/wb-21fd5541-feature-automate-reference-docs-generation/ja/guides/tracking/imgs/video-trace-popout.png)
