Skip to content

Exceptions

Every FFmpeg failure surfaces as a typed exception under FFmpeg\Exception\. Each one carries the failing FFmpeg call and the decoded error text, so you never parse a message string.

PropertyTypeDescription
$operationstringThe FFmpeg API call that failed, e.g. "avcodec_open2".
$avErrorstringThe av_strerror() text for the failing AVERROR, when there was one.

getMessage() returns "{$operation}: {$avError}".

FFmpegException (base — extends \Exception)
├── FileNotFoundException input path did not exist
├── InvalidFormatException opened but not valid/probeable media
├── StreamNotFoundException a requested stream was not present
├── EncoderNotFoundException chosen encoder not built into this FFmpeg
└── EncodingException a failure during encoding / muxing

Catch the base FFmpegException to handle everything, or a leaf for a specific case.

use FFmpeg\Media;
use FFmpeg\Exception\{FileNotFoundException, FFmpegException};
try {
$media = Media::open($path);
} catch (FileNotFoundException $e) {
// handle a missing file specifically
} catch (FFmpegException $e) {
fprintf(STDERR, "ffmpeg failed in %s: %s\n", $e->operation, $e->avError);
}

An Artisan Build project.

Built on FFmpeg — an independent binding, not affiliated with or endorsed by the FFmpeg project.

Proudly sponsored by Tighten.