Build your own simple Video Streaming service
Background:
Four months back, when I was watching some video on Youtube,
suddenly a thought came up to my mind about creating my pet project for video
streaming service. I named it “Punahele” (Hawaiian word for Video :-)). What
proceeded was an awesome development experience that involved using multiple
technologies although the project remains incomplete.
In this post, I will walk you through the technical
aspects of building a custom video service project like this one.
Overall
setup & goals: Before we delve into the project, let me explain you
the goals I had for this project.
·
The video should be streamed seamlessly to the user.
At the same time, the CPU and RAM usage of the server should not shoot up high.
·
The users should be able to resume a previous session
without any issue.
·
Video conversion process should not affect the users
·
A search interface should be provided to the user
· Front End Module: This module is for the User Interface. The User
Interface is mainly written in Bootstrap and JSP. I have chosen Bootstrap
because it is easy to design box design. In Box design, the entire screen is
divided into boxes. The outermost box is the entire page. This is divided into
multiple sub boxes, one box contains Logo, Search box, Control boxes. Then another
box contains the video thumbnails, video information and so on. The box
structure is realized in Bootstrap using many inbuild css classes like “Container”,
“col-sm-*” and so on.
·
Batch Conversion Module: This module runs as a Batch job converting videos into frames. We will see this in depth later.
Batch Conversion Module: This module runs as a Batch job converting videos into frames. We will see this in depth later.
·
Adapter Module: This module is packed with java interfaces for ElasticSearch, Redis and Kafka.
Adapter Module: This module is packed with java interfaces for ElasticSearch, Redis and Kafka.
·
Core Module: This is the main module that will fetch required content and provide them to the front end.
Core Module: This is the main module that will fetch required content and provide them to the front end.
Batch
Conversion Process: The main idea behind converting video to frames is to
have more control on the video portions requested by the user. This can also be
capitalized to have better cache control on the video content. I have used
JCodec library to convert video to frames. It provides a NIOUtils class that
provides a readable channel for the file content. We then pass the channel to
AWTFrameGrab class createAWTFrameGrab method that will return an iterator to
the frames. We can convert the frames to a BufferedImage and write to a file
using ImageIO class.
Here, once I am finished converting videos to frames,
I write all the frames to single file and create a separate file that will hold
the frame positions. I am doing this because this way, it becomes easier to
read random file positions using RandomAccessFile.
Technologies:
Core Java 8, JEE7, WebSockets, Futures, Kafka, Redis,
ElasticSearch, Bootstrap, RandomAccessFile
Comments
Post a Comment