Problem/Motivation

The following error appears after updating composer packages:

PHP Fatal error:  Uncaught TypeError: Argument 3 passed to FFMpeg\FFProbe::create() must be an instance of Psr\Cache\CacheItemPoolInterface or null, instance of Drupal\php_ffmpeg\PHPFFMpegCache given, called in /var/www/html/web/modules/contrib/php_ffmpeg/src/PHPFFMpegFactory.php on line 76 and defined in /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFProbe.php:220
Stack trace:
#0 /var/www/html/web/modules/contrib/php_ffmpeg/src/PHPFFMpegFactory.php(76): FFMpeg\FFProbe::create(Array, Object(Drupal\Core\Logger\LoggerChannel), Object(Drupal\php_ffmpeg\PHPFFMpegCache))
#1 /var/www/html/web/modules/contrib/php_ffmpeg/src/PHPFFMpegFactory.php(63): Drupal\php_ffmpeg\PHPFFMpegFactory->getFFMpegProbe()
#2 [internal function]: Drupal\php_ffmpeg\PHPFFMpegFactory->getFFMpeg()
#3 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(255): call_user_func_array(Array, Array)
#4 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(173): Drupal\Component\DependencyInjection\Container-> in /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFProbe.php on line 220

This seems to be related to a change in the php-ffmpeg/php-ffmpeg package introduced in https://github.com/PHP-FFMpeg/PHP-FFMpeg/commit/7eace8852ac40ff2c38d90d8... which is part of the latest release.

Steps to reproduce

Update composer packages with "composer update"

Proposed resolution

Either lock the version of the dependency to v0.18.0, or alter PHPFFMpegCache to implement Psr\Cache\CacheItemPoolInterface.

Remaining tasks

- choose a resolution
- implement it

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Issue fork php_ffmpeg-3256578

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

semiaddict created an issue. See original summary.

retiredpro made their first commit to this issue’s fork.

retiredpro’s picture

locked the dependency to v0.18.0 as a quick fix.

hatuhay’s picture

StatusFileSize
new269 bytes
arturopanetta’s picture

I started studying the problem, not having much time available, I put some notes for the modification of PHPFFMpegCache. I hope these notes will save me time in the future or for other people who want to take an interest in the solution.

The break is caused at line 76 of getFFMpegProbe()

https://git.drupalcode.org/project/php-ffmpeg/-/blob/8.x-1.x/src/PHPFFMp...

72 public function getFFMpegProbe() {
73   return FFProbe::create(
74      $this->getFFMpegConfig(),
75      $this->logger,
76      $this->cache
77    );
78 }

$this->cache (optional) is an instance of \Doctrine\Common\Cache\Cache instead php-ffmpeg v0.19 accepts the type Psr\Cache\CacheItemPoolInterface.

$this->cache is instantiated in the constructor through a dependency injection.
$this->cache is injected into the PHPFFMpegFactory constructor from a yml services configuration.

https://git.drupalcode.org/project/php-ffmpeg/-/blob/8.x-1.x/src/PHPFFMp...

  /**
   * Constructs a the factory object with injected dependencies.
   *
   * @param \Doctrine\Common\Cache\Cache $cache
   *   The cache backend.
   * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
   *   Prefix used for appending to cached item identifiers.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   A configuration factory instance.
   */
  public function __construct(Cache $cache, LoggerChannelInterface $logger, ConfigFactoryInterface $config_factory) {
    $this->cache = $cache;
    $this->logger = $logger;
    $this->config = $config_factory->getEditable('php_ffmpeg.settings');
  }

After changing the "PHPFFMpegCache" class, the cache type must be changed in the PHPFFMpegFactory constructor. The challenging thing is to implement the cache with Psr\Cache\CacheItemPoolInterface.

Docs: https://api.drupal.org/api/drupal/vendor%21psr%21cache%21src%21CacheItem... (Great documentation page!)

For now I'll stop here, continue as soon as I have some time.

volman’s picture

Status: Active » Needs review
StatusFileSize
new8.2 KB

Reworked PHPFFMpegCache and updated tests. Dropped Doctrine Cache and used Symfony Cache instead. Now we are compatible with php-ffmpeg >=0.19.

vadim s. sabinich’s picture

@volman
I've tried to apply your patch, but after enabling the module I've been found error:
Class "Symfony\\Component\\Cache\\Adapter\\AbstractAdapter" not found in /sites/www/modules/php_ffmpeg/src/PHPFFMpegCache.php on line 11 #0 /sites/www/vendor/composer/ClassLoader.php(571):

volman’s picture

@vadim
The class you mention is a part of Symfony Cache which is a dependency of php-ffmpeg/php-ffmpeg since v0.19.
Until #9 is ported to upstream module, you have to manually add required php-ffmpeg version to your project:
composer require php-ffmpeg/php-ffmpeg ^0.19
Hope this helps.

vadim s. sabinich’s picture

I've been deployed blank test environment with composer

composer require 'drupal/video:^1.5@alpha'
composer require php-ffmpeg/php-ffmpeg ^0.19
composer require 'drupal/local_video_thumbnail:^2.0@alpha'

and after that, then I enabled a local_video_thumbnails (and php_ffmpeg by dependence) and saw error:

[Wed Jun 29 17:35:30.634126 2022] [proxy_fcgi:error] [pid 5633:tid 139812979791616] [client x:0] AH01071: Got error 'PHP message: Error: Interface "Doctrine\\Common\\Cache\\Cache" not found in /sites/dev/web/modules/contrib/php_ffmpeg/src/PHPFFMpegCache.php on line 11 #0 /sites/dev/vendor/composer/ClassLoader.php(571): include()\n#1 /sites/dev/vendor/composer/ClassLoader.php(428): Composer\\Autoload\\includeFile('/sites/dev...')\n#2 /sites/dev/web/core/lib/Drupal/Component/DependencyInjection/Container.php(262): Composer\\Autoload\\ClassLoader->loadClass('Drupal\\\\php_ffmp...')\n#3 /sites/dev/web/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 'php_ffmpeg.cach...')\n#4 /sites/dev/web/core/lib/Drupal/Component/DependencyInjection/Container.php(437): Drupal\\Component\\DependencyInjection\\Container->get('php_ffmpeg.cach...', 1)\n#5 /sites/dev/web/core/lib/Drupal/Component/DependencyInjection/Container.php(240): Drupal\\Component\\DependencyInjection\\Container->resol...', referer: https://dev/web/admin/structure/types/manage/article/display

php 8.0.18

If you have interest for debug this issue, I'll ready grant access for you.

volman’s picture

@vadim It seems you have current (unpatched) version of drupal/php_ffmpeg.

After installing drupal/php_ffmpeg with composer you have to patch it with the file from #9. You can do it manually or you can use composer too.

Share your complete composer.json or you can grant me access to your test environment if you still have trouble.

vadim s. sabinich’s picture

That's really true! I forgot to apply your patch. After these I confirm: Its work!

schoenef’s picture

Thx for #9, it works well :)

mhavelant’s picture

Status: Needs review » Reviewed & tested by the community

Hi, everyone!
I received a mail from @volman that #9 has been tested by many people by now and could be pushed to the codebase, closing the issue.
I'm no longer a Drupal dev, and don't really have the time to apply and push the patch, so if someone would like to take over the maintainer status of the project, feel free to reach out to me. Or, if someone has time to create a MR from the patch, I could probably click it into the codebase from the UI, too.

mhavelant’s picture

I assigned @szato as a maintainer, hopefully he'll have time to take a look at this soon!

aporie’s picture

Thanks a lot Volman for the patch.

With the last version of Drupal 10 I was getting errors from functions not being compatible with Symfony\Component\Cache\Adapter\AbstractAdapter interface.

Attached is a patch to make them compatible. Some might need a few tweaks to respect their return types though, but haven't got time to get there yet.

aporie’s picture

Ok, so as expected, patch #18 is useless because functions don't return their expected return type.

I investigated, and I wonder if Drupal caches are compatible with function definitions in symfony.

If I check in vendor/symfony/cache/Traits/AbstractAdapterTrait.php::doSave(), the function should return @return array|bool The identifiers that failed to be cached or a boolean stating if caching succeeded or not.

Though Drupal backend cache throw errors on failure.

I ended up returning TRUE for each function. At least it does work now.

bhanu951’s picture

Anyone got any suggestion on how to fix this issue. Seems Neither the patch from #9 nor #19 can resolve this issue.

bhanu951’s picture

#9 fixes the issue but only with "php-ffmpeg/php-ffmpeg" version "0.19.0"

aporie’s picture

You should check the version of FFmpeg installed on your server. It's possible you have an incompatibility between the PHP library and your server version.

ffmpeg -version

ivnish’s picture

Patch #19 looks good

Berdir made their first commit to this issue’s fork.

Berdir changed the visibility of the branch 7.x-1.x to hidden.

berdir’s picture

Totally forgot I was a maintainer here. Looking into this now and starting a new MR with the changes.

To be able to test this, I merged in the D10 rector patch from #3297867: Automated Drupal 10 compatibility fixes and also enabled Gitlab CI.

I'm not sure why we allow 0.19 *and* 1.1 at this point, #21 mentions this only works with 0.19, will try to do some real tests now to see how this works.

  • Berdir committed 3c409c30 on 8.x-1.x
    Issue #3256578 by retiredpro, Aporie, volman, hatuhay, vadim s. sabinich...
berdir’s picture

Title: Incompatible with newest version of the php-ffmpeg (v0.19.0) package » Incompatible with newest version of the php-ffmpeg (v0.19.0) package, Drupal 10 compatibility
Status: Reviewed & tested by the community » Fixed

Did some basic tests for our use case, that works with version 1.1. Keeping the version string as it is for now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.