PHP-FFMpeg / PHP-FFMpeg

An object oriented PHP driver for FFMpeg binary
MIT License
4.84k stars 887 forks source link

Undefined array key "streams" when generating thumbnail #873

Open alhaji-aki opened 2 years ago

alhaji-aki commented 2 years ago
Q A
Bug? yes
New Feature? no
Version Used v1.0.1
FFmpeg Version ffmpeg version 2022-07-04-git-dba7376d59-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
OS Windows 11

Actual Behavior

I get an error which says Undefined array key "streams"

Expected Behavior

I expected that thumbnail should have been generated.

Steps to Reproduce

I am using PHP 8.1 and Laravel 9. Below is a code snippet

$ffmpeg = \FFMpeg\FFMpeg::create([
    'ffmpeg.binaries'  => config('media.ffmpeg_path'),
    'ffprobe.binaries' => config('media.ffprobe_path'),
    'temporary_directory' => $temporaryDirectory->path()
]);

$video = $ffmpeg->open($baseFile);
$video
    ->frame(\FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save($thumbnailPath);

$temporaryDirectory->path() returns an absolute path for the temporary directory

$baseFile is the absolute file path for the video file to generate the thumbnail from

$thumbnailPath is also an absolute file path for the thumbnail image.

Possible Solutions

Change the below code snippet in the mapStreams method of FFMpeg\FFProbe\Mapper::42 from

foreach ($data['streams'] as $properties) {
    $streams->add(new Stream($properties));
}

To

foreach ($data['streams'] ?? [] as $properties) {
    $streams->add(new Stream($properties));
}

To take care of instances where no streams are available.

patrik-csak commented 2 years ago

i got this error message and it turned out that the path i passed to $ffpeg->open() was incorrect