DiscordPHP-Voice Documentation

Ffmpeg extends ProcessAbstract
in package

FinalYes

Handles the decoding and encoding of audio streams using FFmpeg.

Tags
since
10.19.0

Table of Contents

Constants

DEFAULT_KHZ  : int = 48000
Default KHz value for voice to be decoded after someone talks.

Properties

$exec  : string

Methods

__callStatic()  : mixed
Guards static `encode()` / `decode()` calls behind an ffmpeg availability check.
__construct()  : mixed
checkForExecutable()  : string|null
Checks if the specified executable is available on the system.
checkForFFmpeg()  : bool
Locates an `ffmpeg` executable on PATH, caching the resolved path in `self::$exec`.
decode()  : Process
Decodes an Opus audio stream to OGG format using FFmpeg.
encode()  : Process
Builds an ffmpeg process that transcodes the input to Opus on stdout (`pipe:1`).

Constants

DEFAULT_KHZ

Default KHz value for voice to be decoded after someone talks.

public int DEFAULT_KHZ = 48000

Properties

$exec

protected static string $exec = '/usr/bin/ffmpeg'

Methods

__callStatic()

Guards static `encode()` / `decode()` calls behind an ffmpeg availability check.

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string

Method being called.

$arguments : array<string|int, mixed>

Forwarded arguments.

Tags
throws
FFmpegNotFoundException

if ffmpeg is not installed.

BadMethodCallException

for any other method name.

checkForExecutable()

Checks if the specified executable is available on the system.

public static checkForExecutable(string $exec) : string|null
Parameters
$exec : string
Return values
string|null

checkForFFmpeg()

Locates an `ffmpeg` executable on PATH, caching the resolved path in `self::$exec`.

public static checkForFFmpeg() : bool
Return values
bool —

True if a usable binary was found.

decode()

Decodes an Opus audio stream to OGG format using FFmpeg.

public static decode([mixed $filename = null ][, int|float $volume = 0 ][, int $bitrate = 128000 ][, int $channels = 2 ][, null|int $frameSize = null ][, null|array<string|int, mixed> $preArgs = null ]) : Process

TODO: Add support for Windows, currently only tested and ran on WSL2

Parameters
$filename : mixed = null

If there's no name, it will output to stdout (pipe:1). If a name is given, it will save the file with the given name. If the name does not end with .ogg, it will append .ogg to the name. If null, it will use 'pipe:1' as the filename.

$volume : int|float = 0

Default: 0

$bitrate : int = 128000

Default: 128000

$channels : int = 2

Default: 2

$frameSize : null|int = null
$preArgs : null|array<string|int, mixed> = null
Return values
Process

encode()

Builds an ffmpeg process that transcodes the input to Opus on stdout (`pipe:1`).

public static encode([string|null $filename = null ][, int|float $volume = 0 ][, int $bitrate = 128000 ][, array<string|int, int|string>|null $preArgs = null ]) : Process
Parameters
$filename : string|null = null

Input filename, or null to read from stdin (pipe:0).

$volume : int|float = 0

Volume adjustment in dB.

$bitrate : int = 128000

Target audio bitrate in bits per second.

$preArgs : array<string|int, int|string>|null = null

Extra arguments placed before the input flags.

Return values
Process
On this page

Search results