Generating Thumbnails from Videos using ApyHub’s API: A step-by-step guide in Go
The tutorial introduces the ApyHub video thumbnail generator API, providing a step-by-step guide on how to utilize the API for requesting video thumbnails using Go.
Last updated on February 06, 2024
As we have discussed in the previous article, video thumbnails have a lot of benefits and possible uses, including better visual appeal, improved user experience, and of course a boost in brand identity and recognition. In this tutorial, we will get a bit more technical - focusing on the ApyHub video thumbnail generator API.
No worries, this will try to be as simple and detailed as possible. We will go step by step, guiding you through every little detail. We will cover the API's core functionalities, including how to request thumbnails from videos using simple HTTP requests.
Moreover, we will show something even more cool: How to custamize thumbnail dimensions and extract thumbnails from various time points within a video. Finally, we will show how to implement the generated thumbnails into your applications or websites.
Step 1: Set up the project
First things first — We’ll start by creating a new directory and initialize it with Go modules.
go mod init video-thumbnail-generator initializes a new Go module by creating a go.mod file in the current directory which tracks the project's dependencies.
Step 2: Create a new file
main.go, and open it in your IDE or code editor:
This file will contain the logic to interact with ApyHub’s Video Thumbnail Generator API.
Step 3: Import the necessary packages:
In this step, the necessary packages are imported to make a successful API call.
- bytes: Required for buffering and manipulating byte slices.
- encoding/JSON: Required for encoding and decoding JSON, the format used for the API request and response.
- fmt: Provides I/O formatting functions.
- net/http: Required to make HTTP requests to the API.
- io/ioutil: Helps in reading the response body
Step 4: Define the payload:
This code defines a struct
ThumbnailRequest representing the data you will send to the API and tells Go how to encode the data into JSON.
Step 5: Creating the HTTP Request:
We are creating a
generateThumbnail function, which will encapsulate the logic to generate Thumbnail using ApyHub’s Generate Video Thumbnail API.
Step 6: Create the main Function:
This function initialises variables for our
apiToken and the
videoURL, then calls the
generateThumbnail function with these parameters to generate a thumbnail for the specified video.
Step 7: Running the Program:
Finally, execute the program by running go run main.go to your terminal.
go run command is used in Go to compile and run a Go program in a single step. allows you to quickly execute a Go source file without explicitly building an executable binary.
This will make an API request to APYHub to generate a thumbnail from the specified video URL, and you should see the API response in your terminal.
Note: You can also find the complete code in this repository. Also, if you’re looking for a NodsJS integration guide, you can find it here.
That's it! It wasn't so difficult, right? We have successfully integrated the Video Thumbnail API using Go Lang!
Using this service, we can generate video thumbnails from literally any part of a video file or URL (e.g. YouTube). This way, we automate extracting thumbnails from videos, allowing for efficient and consistent extraction of thumbnails without the need for any manual work.
The ApyHub Video Thumbnail API can also be integrated into existing workflows and platforms, making it easy to incorporate thumbnail extraction into existing processes.
Good luck with using the API. Looking forward to any feedback on Discord.