I’ve built an application in Golang, which is able to find video content from all of the videos that have been uploaded to the application. It utilises the Google Cloud Video Intelligence API to detect the features (content) inside the video.
Category Submission:
I decided to submit my application into multiple categories. Below is a list of all of the categories that I would like to submit my application in, as well as description as why I think the app can be submited into listed category.
Search No More:
Main feature of the application is to perform a quick search on ALL of the uploaded videos. That’s why I used Atlas Search, as it provides quick setup and is querying super fast.
Think Outside the JS Box:
As an backend developer, it was my goal for quite some time now to learn Golang, but I was procrastinating with learning Go, that’s why decided that the best way to learn new programming language is to build something with it. That’s why I picked Golang as my API language.
Google Cloud Superstar:
The “brains” behind the Video Feature detection Google Cloud Video Intelligence API, which provides Golang SDK and enables the developer to utilise powerful Google Cloud ML engine to detect the video features.
App Link
Because I use Google Cloud Video Intelligence API, which is not free, I did not want to post my application publicly and create some “unwanted” costs on my Google Cloud bill 😃. However, I recorded a short demo video, as well as screenshoted the application. After all, if you would like to try my app, you can always clone Git repo, add your Google Cloud credentials, and run the API.
Video
Screenshots
Background
My main motivation to build this application was to learn a few things:
learn how to implement MongoDB into application using SDKs and libraries, and also connect Atlas Search
learn how Google Cloud Video Intelligence works
learn new programming language (Golang)
How I built it
I started my project with developing API server in Golang. For the HTTP library I used Gin framework, as it provides an friendly interface to build REST ready API.
For my application, two endpoints were enough. One was used for video upload, and one for video search. This is how endpoints are defined in Gin:
funcmain(){r:=gin.Default()r.POST("/videos",Controllers.VideoStore)r.GET("/videos",Controllers.VideoSearch)err:=r.Run()iferr!=nil{log.Fatalf(err.Error())return}fmt.Println("Server running on :8080")}
Video upload and feature detection
Video store method consists of the folowing steps:
File upload and transfer to Google Storage Buckets
User can upload the video to our API. Our API then uploads it to the Google Storage Bucket. This is the code that accomplishes that:
// ...// Client init, ...// ...f,uploadedFile,_:=c.Request.FormFile("video")iffilepath.Ext(uploadedFile.Filename)!=".mp4"{c.JSON(http.StatusUnprocessableEntity,gin.H{"error":"Uploaded file must be mp4 video",})return}// Upload file to Storage Bucketsw:=Services.StorageBucket.Object(fileUuid.String()).NewWriter(ctx)_,err=io.Copy(sw,f)err=sw.Close()iferr!=nil{return}
Uploaded file is added as an record to the MongoDB database, so we can reference it later. We save video file name, size and unique UUID, which we can reference when retrieving the private object.
3.File can be sent to Google Video Intelligence API, and retrieve the video features.
// ...op,err:=client.AnnotateVideo(ctx,&videopb.AnnotateVideoRequest{InputUri:"gs://"+os.Getenv("GOOGLE_CLOUD_STORAGE_BUCKET")+"/"+fileUuid.String(),Features:[]videopb.Feature{videopb.Feature_LABEL_DETECTION,},})iferr!=nil{log.Fatalf("Failed to start annotation job: %v",err)}resp,err:=op.Wait(ctx)iferr!=nil{log.Fatalf("Failed to annotate: %v",err)}result:=resp.GetAnnotationResults()[0]
Retrieved features are saved to the corresponding video entity in MongoDB database, where Atlas search can index them.
I left the Atlas Search parameters as default, as I discovered that they work great for my usecase. They search across all of the saved video features:
# create and update .env file
$ cp .env.example .env
# install dependencies
$ npm install
# serve with hot reload at localhost:3000
$ npm run dev
# build for production and launch server
$ npm run build
$ npm run start
# generate static project
$ npm run generate
I really enjoyed building this application, as I discovered and learned a lot about MongoDB, as well as Google Cloud APIs. I was also fascinated about ease of use of Atlas Search, as it basically worked out-of-the-box (well, for my use-case, anyways). I will deffinietly use MongoDB for some of my personal projects in the future.