Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara28580's avatar

Make sure Vimeo has completed transcoding of video on uploading

I know its not really laravel related but maybe has used the laravel vimeo bridge package. My question is how to make sure a video is accessable and ready to work.

Here I am uploading the video to vimeo

$uri = Vimeo::upload($file, ['name' => $request->title], 'POST'); //upload video and get unique identifier

In my $uri I get the transcoding status "complete" , "in_progress", "error" I could check for. But how would I implement such a check should I use something like a sleep function and check after 2 or 3 mins if the video is ready? I have never done something like that before.

Something like that

sleep(5000);

if(status === complete) {}...

or

do {
//nothing
}while (status === "in_progress")

You get the Idea?

Best

0 likes
7 replies
lara28580's avatar

I tried it like so now but I dont really know if this is the way to go...

 do {

          sleep(60);

 } while($response['body']['transcode']['status'] === 'in_progress');

Or is this bad practice?

EDIT: If it takes too long then I get Maximum execution time of 120 seconds exceeded

guybrush_threepwood's avatar

Hi @smoketm

Since Vimeo doesn't seem to have a notification webhook, this is what I would do:

  1. Create a videos table with a processed column (default: 0) and store the video $uri after the video finishes uploading.

  2. Setup a scheduled job that runs every minute (no overlapping) to poll Vimeo for all unprocessed videos. If a video is found to be complete, set processed=1 and notify the user via Polling, Websockets or Pusher.

PS: You can also use Livewire to poll your server without reloading the page:

https://laravel-livewire.com/docs/polling

1 like
guybrush_threepwood's avatar
Level 33

Hi @smoketm

Why not apply the global scope to the processed column? That would be cleaner and more precise:

    static::addGlobalScope('processed', function (Builder $builder) {
        $builder->where('processed', true);
    });

Then on your job service you remove the global scope just for this case:

$unprocessedVideos = Video::withoutGlobalScopes()->where('processed', false)->get();

Polling the Vimeo API every minute (or every five minutes), with no overlapping and only for unprocessed videos shouldn't be that bad for performance. Better than having the upload scripts running for minutes and checking on a loop I imagine.

1 like
lara28580's avatar

Thanks this makes sense. This form is not for users only for admins. So the process could take some time.

In your scenerio I would then iterate over the $unprocessedVideos and check with

foreach($unprocessedVideos as $unprocessedVideo) {
$response= Vimeo::request($unprocessedVideo->uri . '?fields=transcode.status', null, 'GET');
  if($response['body']['transcode']['status'] === 'complete') {
     	 $unprocessedVideo->processed = true;
  }
}

EDIT: And what about the videos which have an transcoding status of error? How should I handle that case? Maybe you have an idea. Because I need to know that in the upload process.

martinbean's avatar

@smoketm How are you actually uploading videos? Surely any PHP process is going to time out before it’s finishing “uploading” a video? Especially if that video’s HD or more than a few seconds long.

I operate a video on demand website and a video is uploaded (to S3) in chunks using JavaScript. I then have SNS notifications to notify me when the video has finished transcoding. I’m surprised Vimeo doesn’t offer a web hook for this and you instead have to poll.

To avoid unnecessary re-polling, it might be an idea to do polling based on the size of the video. If it’s a small video, you could poll more frequently than if you were to upload a video that was say, 2 hours long. I imagine transcoding takes longer, the larger the video, so you can assume a long video is going to take a little time to transcode and you don’t need to ping Vimeo every minute; maybe ping Vimeo every 5 minutes instead.

1 like
lara28580's avatar

yeah I am using a package which provides some methods to upload to vimeo like so

$uri = Vimeo::upload($file, ['name' => $request->title], 'POST');

I then save the uri to my db and so on.... I understand what you mean but I dont know if its necessary for our plattform because only admins can upload the video and I can say a video is max 30mins long. At least for the beginning I think I could do it like I do it. Maybe later on I have to refactor some things.

Ranx99's avatar

@smoketm I have a similar case, just curious on how did you solve the issue? since Vimeo doesn't support webbooks

Please or to participate in this conversation.