File.create:after hook fails on executing a ffmpeg command on live server

Hi there,

on my site I am using a file.create:after hook to create video thumbnails for videos that the editor uploads. Here is the thread were I got the code from.

The relevant code part looks like this:

'file.create:after' => function ($file) {
      $filetype = $file->type();

      if($filetype === 'video') {
        // extract thumbnail from video file
        try {
          exec('ffmpeg -y -i ' . $file->root() . ' -ss 3 -t 1 -s 320x180 ' . $file->parent()->root() . '/' . F::name($file->filename()) . '_thumb.jpg');

        } catch(Exception $e) {
          echo 'Video thumbnail could not be extracted.';
          echo $e->getMessage();
        }
      }
    }

This works in my local setup, but it fails on my live server setup.
I do have ffmpeg set up on my live server, so I can connect to the server via ssh and then use ffmpeg there via the terminal. However, the thumbnails don’t get created on newly uploaded videos.

Since I have to turn off debugging on the live server now I don’t even know how to find out what is going wrong. Is it possible that the $file->root() command does not extract the correct path on the live server? If so, how could I find out about that?

Or does anybody have any idea what else could be wrong?

Thanks!

Echoing something in the catch block doesn’t make sense inside a hook. Try writing something to file instead. Maybe the exec() command is blocked on the server?

On a side note: Turning debugging off in the config doesn’t mean you cannot do any debugging anymore. For one thing, you could still turn it on for testing. But IRL, you would set your php.ini up to log errors instead of displaying them on screen.

Having said that, hooks usually don’t throw errors, so using error_log() or F::write() will probably be more useful here.