Streaming
Streaming is the continuous transmission of video files from a server to a client.
Last updated
Streaming is the continuous transmission of video files from a server to a client.
Last updated
Streaming with CLI
Video streaming with Zbox CLI can be implemented with players for different operating platforms(iOS, Android Mac). Zbox CLI does not have a player itself and uses the downloadFileByBlocks
helper function to properly returns file-chunks with the correct byte range.
How it works:
When the user starts the video player (ExoPlayer for Android or AVPlayer for iOS), A ZChainDataSource starts chunked download and requests chunks of video from the buffer(a Middleman between the streaming player and Zbox).
After the arrival of the first chunk, the player starts requesting more chunks from the buffer, which requests the Zbox SDK. Zbox SDK, which is built using GO, makes use of the downloadFileByBlocks method to reliably download large files by chunking them into a sequence of parts that can be downloaded individually.
Once the blocks are downloaded, they are read into input streams and added to the media source of the streaming player.
The task of downloading files and writing them to buffer using Zbox SDK happens constantly, and If players request random bits of video, they are delivered instantly by a buffer.
In a case, if the player didn't receive chunks (for example, it's still not downloaded), then the player switches to STALE state, and the video stream will pause.
During the STALE state, a player tries to make multiple requests for chunks; if didn't receive a response, the video stream stops.
Usage
To understand how Zbox CLI provides downloading of files by blocks. Let's consider an allocation that has audio. mp3
file stored on dStorage. Make sure the file has a large size(more than 64 kB(64000 bytes)) to download the file by blocks. The size and other attributes of the sample audio. mp3
file can be viewed using
Response:
Here we can see the audio.mp3
file of size (5993286) bytes having 92 blocks.If we want to download a certain number of blocks for the audio.mp3
file we can use the --endblock
or --startblock
flag with ./zbox download
command. Other flags for download can be viewed using ./zbox download --help
For only downloading three blocks of audio.mp3
file, we specify --startblock
and--endblock
with integer value of 1 and 3. --blockspermarker
flag can also be specified to download multiple blocks at a time(default is 10).
Sample command for downloading till 3rd block of the audio.mp3
file would be:
Response:
As we can see, the downloaded file size(393216) is less than the original(2996198), which means zbox has downloaded some blocks of the file.
Streaming with Web
Streaming with Web works differently from local video players. streaming is implemented with Media Source Extensions (MSE) as a serverless solution.
The Media Source API, formally known as Media Source Extensions (MSE), provides functionality enabling plugin-free web-based streaming media. Using MSE, media streams can be created via JavaScript, and played using
<audio>
and<video>
elements.
if the mime codec of a video file is supported in MediaSource, eg fMP4, WebM, it will be download chunks by chunks from dStorage, and transcode chunks into segments by muxjs.mp4.Transmuxer
, and append them to the SourceBuffer
of MediaSource
of a <video> element.
if the mime codec of a video file is not supported in MediaSource, it has to be transcoded it into fMP4 or WebM on uploading in CLI/APPs. if it is not transcoded, it has to be downloaded fully before playing. so streaming player will not work on it.