# FFmpeg

{% hint style="warning" %}
注意: この機能は Eagle 4.0 beta 7 以降でのみ使用できます。
{% endhint %}

## FFmpeg Dependency Pluginの紹介

"FFmpeg Dependency Plugin"は、ブラウザプラグイン開発者向けのツールキットで、FFmpegの強力なマルチメディア処理機能を使いやすい依存パッケージにカプセル化しています。このツールキットを使用すると、開発者は自分のプラグインで画像、ビデオ、オーディオ形式のエンコードとデコード、ストリーミングメディア処理、形式変換などの高度な機能を簡単に実装できます。"FFmpeg Dependency Plugin"を統合することで、開発者は自分のプラグインのマルチメディア処理機能をシームレスに拡張し、ユーザーにより創造的で実用的な機能を提供できます。

## FFmpeg Dependency Pluginのインストール

1. プラグインセンターに入る
2. FFmpegプラグインを検索して見つける
3. FFmpegプラグインをインストールするためにクリックする

{% hint style="info" %}
ユーザーがFFmpeg依存性のあるプラグインをインストールすると、Eagleは自動的にユーザーに"FFmpeg Dependency Plugin"のインストールを促します。したがって、開発者はユーザーがインストールするための特定のコードを書く必要はなく、可能なエラーに対して対応するプロンプトを提供するだけでよいです。
{% endhint %}

## FFmpeg Dependency Pluginの使用方法

プラグインでFFmpeg関連の機能を使用したい場合は、プラグインの`manifest.json`ファイルに`dependencies`定義を追加する必要があります。これにより、Eagleシステムはこのプラグインが追加の拡張機能を必要とすることを認識します。以下に示します：

```json
{
    "id": "LBCZE8V6LPCKD",
    "version": "1.0.0",
    "platform": "all",
    "arch": "all",
    "name": "Window Plugin",
    "logo": "/logo.png",
    "keywords": [],
    "dependencies": ["ffmpeg"],
    "devTools": false,
    "main":
    {
        "url": "index.html",
        "width": 640,
        "height": 480,
    }
}
```

### Window Pluginの例 <a href="#gylpl" id="gylpl"></a>

以下に示すように、`eagle.extraModule.ffmpeg`を使用してFFmpeg依存プラグインが提供する機能を呼び出すことができます：

```javascript
eagle.onPluginCreate(async (plugin) => {

    // FFmpeg依存プラグインがインストールされているかどうかを確認します
    const isFFemptInstalled = await eagle.extraModule.ffmpeg.isInstalled();
    
    // プラグインセンターを開き、FFmpeg依存プラグインのインストールページをポップアップします。
    if (!isFFemptInstalled) {
        await eagle.extraModule.ffmpeg.install();
        return;
    }
    
    // FFmpegバイナリファイルの場所を取得します
    const ffmpegPaths= await eagle.extraModule.ffmpeg.getPaths();
    const ffmpegBinaryPath = ffmpegPaths.ffmpeg;
    const ffprobeBinaryPath = ffmpegPaths.ffprobe;
    
    // spwanコマンドを使用して関連操作を行います
    const spawn = require('child_process').spawn;
    const ffprobe = spawn(ffprobePath, [
	'-v', 'error',
	'-print_format', 'json',
	'-show_format',
	'-show_streams',
	"C:\\your_file.mp4"
    ]);
});
```

### Thumbnail Pluginの例 <a href="#gylpl" id="gylpl"></a>

以下に示すように、`extraModule`パラメータを通じてFFmpeg関連の機能を取得することができます：

```javascript

module.exports = async ({ src, dest, item, plugin, extraModule }) => {
    return new Promise(async (resolve, reject) => {
        try {
        
            const ffmpegModule = extraModule.ffmpeg;
	
            // FFmpeg依存プラグインがインストールされているかどうかを確認します
            if (!ffmpegModule.isInstalled) {
		return reject(new Error(`ffmpeg is not installed.`));
	    }
	    
            // FFmpegバイナリファイルの場所を取得します
            const { ffmpeg, ffprobe } = ffmpegModule.paths;
            
            // spwanコマンドを使用して関連操作を行います
            const spawn = require('child_process').spawn;
            const ffprobe = spawn(ffprobePath, [
	        '-v', 'error',
        	'-print_format', 'json',
	        '-show_format',
	        '-show_streams',
	        "C:\\your_file.mp4"
            ]);
            
            return resolve(item);
        }
        catch (err) {
            return reject(err);
        }
    });
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.eagle.cool/plugin-api/ja-jp/extra-module/ffmpeg.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
