使用 GrabzIt的Node.js API 轉換在線視頻 into動畫GIF。 但是,您必須記住,對於以下任何示例,要創建動畫GIF, save or save_to 方法必須在 url_to_animation 方法。
唯一需要的參數是要轉換的MP4,AVI或其他在線視頻的URL into動畫GIF url_to_animation
方法。
client.url_to_animation("http://www.example.com/video.avi"); //Then call the save or save_to method
使用GrabzIt的Node.js API將Vimeo或YouTube視頻直接轉換為GIF動畫,只需指定顯示Vimeo或YouTube視頻的頁面的URL,然後轉換其中包含的視頻 into動畫GIF。 但是,由於此服務依賴第三方網站,因此不能保證每個視頻都可以使用。
client.url_to_animation("https://www.youtube.com/watch?v=a1Y73sPHKxw"); //Then call the save or save_to method
您可以將自定義標識符傳遞給 url_to_animation 方法,如下所示,然後將該值傳遞回您的GrabzIt Node.js處理程序。 例如,該自定義標識符可以是數據庫標識符,從而允許將動畫GIF與特定的數據庫記錄相關聯。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.url_to_animation("https://www.youtube.com/watch?v=a1Y73sPHKxw", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
從視頻中捕獲單個幀,您需要將持續時間和每秒幀數參數設置為1。 然後,您可以通過設置開始位置參數來獲得所需的幀。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"start":3, "duration":1, "framesPerSecond":1}; client.url_to_animation("http://www.example.com/video.avi", options); //Then call the save or save_to method client.save_to("result.gif", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });