vimeo.js icon indicating copy to clipboard operation
vimeo.js copied to clipboard

Is there any callback or web-hook when the processing is finished ?

Open shammi-hak opened this issue 5 years ago • 19 comments

I uploaded the video to Vimeo and it succeeds. but when I using the URL, It seems like the video still processing that video. So Is there any callback or web-hook to notified me back when it finished the processing.

shammi-hak avatar Oct 28 '19 07:10 shammi-hak

Paying business user here and I definitely agree a webhook for when videos are done processing would be really, really helpful.

With the way the API works currently, I have to continually poll the Vimeo API until the video is done processing. I really don't think this is optimal.

unicornsoftwareinc avatar Nov 05 '19 20:11 unicornsoftwareinc

same here... this is not cost effective even for vimeo. lots and lots of users pinging their server

fweffort avatar Nov 16 '19 17:11 fweffort

any solution found on this?

Tariqali13 avatar Jan 11 '20 07:01 Tariqali13

@Tariqali13 what I suggest doing is as soon as video is uploaded create db entry for that uri with status of "in_progress" then run a cronjob every minute what you do in cronjob is check db for any videos which are of status "in_progress" make get request to https://api.vimeo.com/me/videos?fields=uri,transcode.status and map the response to object and update the "in_progress" docs with new status which might be "in_progress", "complete" or "error"

const unprocessedSnapshot = await admin
	.firestore()
	.collection('videos')
	.where('status', '==', 'in_progress')
	.get();

const unprocessedDocs = unprocessedSnapshot.docs;

if(!unprocessedDocs.length) return null;

const response = await axios(
	'https://api.vimeo.com/me/videos?fields=uri,transcode.status',
	{
		headers: { Authorization: 'bearer 4e01e30bfyouraccesstokenhere7013642b6' },
	}
);

interface MapInterface {
	[key: string]: {
		status: string,
	}
}

const map: MapInterface = {};

for (const item of response.data.data) {
	map[item.uri] = {
		status: item.transcode.status,
	};
}

for (const doc of unprocessedDocs) {
	const video = doc.data();

	await admin
		.firestore()
		.collection('videos')
		.doc(doc.id)
		.update({
			...map[video.uri]
		});
}

pavanjadhaw avatar Apr 12 '20 04:04 pavanjadhaw

@pavanjadhaw thanks. that's a good solution but hope in future we will get a callback by vimeo

Tariqali13 avatar Apr 12 '20 07:04 Tariqali13

I bet that if Vimeo wants, a lot of coders would help to implement the webhook feature. I would. This is sooooo needed.

And again. Lots of “pinging” on the server versus one call to the webhook would unclutter services.

fweffort avatar Jul 04 '20 11:07 fweffort

Can anyone from Vimeo comment on this? This feature would really be enormously helpful.

unicornsoftwareinc avatar Oct 21 '20 18:10 unicornsoftwareinc

Hi, i have found that bit of undocumented useful code while browsing the repo examples:

client.upload(
  filePath,
  params,
  function (uri) {
    // UPLOAD SUCCESS but NOT TRANSCODED
    // Get the metadata response from the upload and log out the Vimeo.com url
    client.request(uri + '?fields=link', function (error, body, statusCode, headers) {
      if (error) return console.error('There was an error making the request.')
      console.log('"' + filePath + '" has been uploaded to ' + body.link)

        // Make an API call to see if the video is finished transcoding.
        client.request(
          uri + '?fields=transcode.status',
          function (error, body, statusCode, headers) {
            if (error) return console.error('There was an error making the request.')
            console.log('The transcode status for ' + uri + ' is: ' + body.transcode.status)
          }
        )
      })
    })
  },
  function (bytesUploaded, bytesTotal) {  },
  function (error) { }
)

You can start from this example to find a way to check for uploaded AND transcoded status for the video ^^

top-kat avatar Nov 18 '20 09:11 top-kat

Hi, i have found that bit of undocumented useful code while browsing the repo examples:

client.upload(
  filePath,
  params,
  function (uri) {
    // UPLOAD SUCCESS but NOT TRANSCODED
    // Get the metadata response from the upload and log out the Vimeo.com url
    client.request(uri + '?fields=link', function (error, body, statusCode, headers) {
      if (error) return console.error('There was an error making the request.')
      console.log('"' + filePath + '" has been uploaded to ' + body.link)

        // Make an API call to see if the video is finished transcoding.
        client.request(
          uri + '?fields=transcode.status',
          function (error, body, statusCode, headers) {
            if (error) return console.error('There was an error making the request.')
            console.log('The transcode status for ' + uri + ' is: ' + body.transcode.status)
          }
        )
      })
    })
  },
  function (bytesUploaded, bytesTotal) {  },
  function (error) { }
)

I found this could be useful ^^

Sorry to say, but you didn't understand the problem

algosoftbd avatar Mar 16 '21 16:03 algosoftbd

Been a paying business user for about 2 years now and still no solution for this yet. I still have my polling solution in place but it would really be so much better if Vimeo implemented some sort webhook/callback feature here.

unicornsoftwareinc avatar Jun 24 '21 20:06 unicornsoftwareinc

A webhook is available by default in a lot of services nowadays. It'd be very useful to be notified by Vimeo if a video was uploaded/changed. We could even pay a bit extra for this feature (although it should not put too much toll on their systems).

In my case I'd like to keep my custom apps and their service in sync. So, for example, whenever something happens to a video via Vimeo's UI my app would be notified so it could do additional processing.

Wondering if there is a way to make this more visible to Vimeo since it's not javascript specific.

iSeiryu avatar Aug 27 '21 21:08 iSeiryu

Not sure but to be honest I am considering switching video hosting services. This library seems completely abandoned at this point and video uploads are an important feature for my business. It would be nice to know that the library I am using (as a paying customer) is at the very least being maintained.

2023 edit: Our business switched over to using Bunny.net which has a really easy to use API for video uploads and management. And as an added bonus, it’s 5 - 10x cheaper compared to the enterprise plan that Vimeo forced us onto a few years ago.

unicornsoftwareinc avatar Oct 01 '21 00:10 unicornsoftwareinc

are there any updates on this? also what would be a good alternative to Vimeo? Dev support is more important than price EDIT: I'm using mux, it's great and does support webhooks

rubenheymans avatar Jun 25 '22 23:06 rubenheymans

@rubenheymans Azure Media Services is a good product. It gives more control over the process but is more complex to setup. It also came out cheaper (for our project) than Vimeo. And Azure support is good. https://azure.microsoft.com/en-us/services/media-services/

iSeiryu avatar Jul 07 '22 14:07 iSeiryu

Currently the only way to view when a video completes transcoding is by polling, i.e. GET /videos/{video_id}?fields=status

If you'd like to see a Webhook interface, please request it at:

https://vimeo.com/help/contact

aaronm67 avatar Jul 19 '22 14:07 aaronm67

Since this status field appears to be undocumented (or hidden somewhere in the API docs that I could not find after looking for 10 minutes), here is the TypeScript type of the response body that you would get from there, scraped together from some 3rd-party Java docs:

// GET /videos/{video_id}?fields=status

type VimeoVideoStatusResponse = {
  status:
    | 'available'
    | 'quota_exceeded'
    | 'transcode_starting'
    | 'transcoding'
    | 'transcoding_error'
    | 'uploading'
    | 'uploading_error';
};

karlhorky avatar Jul 21 '22 11:07 karlhorky

status is documented here: https://developer.vimeo.com/api/reference/response/video, if you scroll down about half the page you'll see it / what each state means.

aaronm67 avatar Jul 21 '22 12:07 aaronm67

Workaround

In case this is useful for anyone else, polling using a recursive async function that calls GET /videos/{video_id}?fields=status and then only resolves once an error occurs or the transcoding is done could be done like this (TypeScript):

// Docs: https://developer.vimeo.com/api/reference/response/video#:~:text=available%20%2D%20The%20video%20is%20available.,an%20error%20in%20uploading%20the%20video.
export type VimeoVideoStatus =
  | 'available'
  | 'quota_exceeded'
  | 'total_cap_exceeded'
  | 'transcode_starting'
  | 'transcoding'
  | 'transcoding_error'
  | 'unavailable'
  | 'uploading'
  | 'uploading_error';

/**
 * Get the transcode status of a Vimeo video
 */
export function getStatusByVideoIdRecursive(videoId: number): Promise<
  | {
      errors: Errors,
    }
  | {
      status: VimeoVideoStatus,
    },
> {
  return new Promise((resolve, reject) => {
    client.request(
      `/videos/${videoId}?fields=status`,
      (error, response: { status: VimeoVideoStatus }) => {
        if (error) {
          return reject(error);
        }

        if (['transcode_starting', 'transcoding'].includes(response.status)) {
          return resolve(
            new Promise((resolveInner) => {
              setTimeout(
                () => resolveInner(getStatusByVideoIdRecursive(videoId)),
                1000,
              );
            }),
          );
        }

        resolve({
          status: response.status,
        });
      },
    );
  });
}

karlhorky avatar Jul 21 '22 12:07 karlhorky

Here's an updated version of the script above, using @vimeo/[email protected] with the promises API:

  • https://github.com/vimeo/vimeo.js/issues/104#issuecomment-1658025556

karlhorky avatar Jul 31 '23 09:07 karlhorky