wp-cli / eval-command

Executes arbitrary PHP code or files.
MIT License
8 stars 15 forks source link

Fatal error when calling PHP-FFMpeg #50

Closed gregoriopellegrino closed 3 years ago

gregoriopellegrino commented 4 years ago

Bug Report

Describe the current, buggy behavior

I am using the PHP-FFMpeg package, installed via composer. When I call the function that uses it with wp eval, the execution stops with error:

Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, null given, called in phar:///usr/local/bin/wp/vendor/symfony/process/ProcessBuilder.php on line 275 and defined in wp-content/plugins/generate-hls/vendor/symfony/process/Process.php:140
Stack trace:
#0 phar:///usr/local/bin/wp/vendor/symfony/process/ProcessBuilder.php(275): Symfony\Component\Process\Process->__construct()
#1 wp-content/plugins/generate-hls/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessBuilderFactory.php(172): Symfony\Component\Process\ProcessBuilder->getProcess()
#2 wp-content/plugins/generate-hls/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(136): Alchemy\BinaryDriver\ProcessBuilderFactory->create()
#3 wp-c in wp-content/plugins/generate-hls/vendor/symfony/process/Process.php on line 140

If I launch it from web interface, it works without problems.

Describe how other contributors can replicate this bug

function test_ffmpeg() {
    $args = array(
      'post_type'      => 'attachment',
      'post_mime_type' => 'video',
      'posts_per_page' => -1,
      'post_status'    => 'inherit',
      'suppress_filters' => true
    );

    require_once(__DIR__ . '/vendor/autoload.php');

    $attachements = new WP_Query($args);
    foreach($attachements->posts as $attachment) {
      $source_file = get_attached_file( $attachment->ID);
        if(!file_exists($source_file)) return false;
        $ffprobe = FFMpeg\FFProbe::create();
        $metadata = $ffprobe->streams($source_file);
        var_dump($metadata->audios()->count());
    }
}

Describe what you would expect as the correct outcome

Get the correct information from ffmpeg.

Let us know what environment you are running this on

OS:     Linux 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64Shell:  /bin/bash
PHP binary:     /usr/bin/phpPHP version:    7.4.5
php.ini used:   /etc/php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/generate/web/generate.staging.effata.it/public_html/wp-content/plugins/generate-hls
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
schlessera commented 4 years ago

This seems to be completely unrelated to WP-CLI. From what I can gather from the error message, it seems to be a bug in the https://github.com/alchemy-fr/BinaryDriver package, which calls the Symfony Process component in an incompatible way. If it is not compatible with some versions of the Symfony Process component, it should state so in its own requirements.