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.
Since Vimeo doesn't seem to have a notification webhook, this is what I would do:
Create a videos table with a processed column (default: 0) and store the video $uri after the video finishes uploading.
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:
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.
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.
@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.
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.