Menu Icon Close
App Development

Zencoder Cloud Encoding

Blog: Zencoder Cloud Encoding feature Image
February 20, 2014
By Barkat Dhillon
Reading Time: 8 minutes

1. Internet has evolved

Internet has changed! Look at the first website ever created and then look at Youtube. That’s some difference in the last 13 years, no? The difference is in the content and delivery. From a bunch of links the sites nowadays have images, forms and yes, videos!
So that begs the question how does a site like youtube work? How do videos get stored and then delivered over multiple devices.

2. Videos?

Users are using different devices for viewing videos online. Mobile device usage is increasing and the device market is growing more fragmented and complex. For mobile devices high resolution heavy video files are inefficient and unnecessary. The quality of the videos vary from HD video for Desktop to light weight video for mobile devices.
The source video file could be of various types i.e.(.mov, .flv, .mp4, .ogg, .wmv). All types are not supported by all devices. This fragmentation means means you need to decide which devices you want to cater to. Thereafter you need to choose the output video formats. There’s Desktop operating systems like Windows. Linux and Mac and then there are mobile operating systems like Blackberry, Windows Phone, Symbian, Android and of course iOS.
But wait that’s not all. You not only need different output formats and video player support but you also need images!
Every video needs thumbnails which can be used as banner images, typically on of the frames of the video.
The videos may need to be branded by adding the company logo as watermarks on each video, which means either water mark is added while recording of the original video or add watermark while adding to your content repository.

3. Enter Encoding!

bmcldrev
Video encoding is your magic wand and does all of the above and more. Encoding is the process of converting digital video files from one format to another.  All of the videos we watch on our computers, tablets, mobile phones must go through an encoding process to convert the original “source” video to be viewable on these devices.  Why?  Because different devices and browsers support different video formats.  This process can also be called “transcoding” or “video conversion“. Here, we will discuss video encoding through Zencoder. Let me first give a brief idea about features of Zencoder.

3.1- Input File Support

Its platform successfully encodes 99.9% of input formats

  • Support nearly every format and codec (See list)
  • Auto rotation for rotated content (including iPhone video)
  • Manual rotation to either forced horizontal or forced vertical
  • Correction for A/V sync issues
  • High quality deinterlacing
  • Improved support for format edge cases (like Quicktime edit Lists)

3.2- Output File Support

It creates high quality video outputs for every major device.

3.2.1- Formats

MP4, 3GP, OGG, WMV, FLV, WEBM, TS, MP3, Apple HTTP Live Streaming (HLS), Microsoft Smooth Streaming (MSS). All Formats

3.2.2- Codecs

H.264 (Baseline, Main, High), AAC (AAC-LC, HE-AAC, HE-AAC v2), MP3, MPEG4, Theora, VP6, VP8, WMV, Vorbis, WMA. All Codecs

3.2.3- Additional Output Features

Device Profiles

Take advantage of presets that target a specific device or a set of devices

Multiple Outputs

Create multiple versions of a video from a single input file

Captions

Provide closed captioning for the hearing impaired audience

 

Transmuxing

Change the container format of H.264 files while keeping underlying streams intact (used for HTTP Live Streaming).

Advanced Thumbnail Options

  • Generate multiple thumbnails per output
  • Choose thumbnail count, interval, or specific times to get the exact frame distribution
  • Crop, size and pad thumbnail images

4- Technical Implementation

In this section we will learn how to encode video, with different format outputs, generate thumbnails, apply watermark on encoded videos.

4.1- Create a Job

For creating any Zencoder request, you need api-key and input and send a post request to https://app.zencoder.com/api/v2/jobs. Zencoder-Api-Key sent as header information with every request, request can have optional output-settings as well (which we will discuss later). It currently supports downloading files using HTTP/HTTPS, S3, Cloud Files, FTP/FTPS, SFTP, and Aspera.

4.1.1- Input Request Body

{
"input": "s3://bluepi-original.s3.amazonaws.com/sample.mov"
}

You can test this with cURL.
[code]
curl –header “Zencoder-Api-Key: 93h630j1dsyshjef620qlkavnmzui3”
–data ‘{“input”:”s3://bluepi-original.s3.amazonaws.com/sample.mov”}’
https://app.zencoder.com/api/v2/jobs
[/code]
Note for Windows users: Due to a limitation in cURL on Windows you’ll need to escape double quotes like ” and wrap the –data content in double quotes instead of single quotes.
This request will create an encoding job for the account and attempted to download and transcode the file at s3://bluepi-original.s3.amazonaws.com/sample.mov to the default output destination.
Note: you need to set S3 credentials in Zencoder account so that it can download source videos and uploaded output files like Thumbnails and Videos.

4.1.2- Response

When you create a new encoding job through the API, Zencoder server will immediately respond with details about the job and output files being created. You should store the job and outputs IDs to track them through the encoding process.
The data will be returned in the JSON format by default. For an XML response, pass format=xml in the querystring, like https://app.zencoder.com/api/v2/jobs?format=xml.
The above encoding job example would return the following, with a 201 Created status code.

{
"id": "1234",
"outputs": [{
"id": "4321"
}]
}

Note: This does not mean that the job will succeed, only that the API request was valid. The job may still fail because the input file does not exist, the output location is invalid, the file itself is not a valid video or audio file, or other reasons.

4.2- Zencoder Request Body Structure

In this section, we will discuss structure of encoding job request.

4.2.1- Input

This is source video which we want to encode and we have seen a simple example above about it.

4.2.2- Notification

When encoding job completes, you can get that information in different ways.

  • You can check the Zencoder Dashboard for job status.
  • You can check job status via a Job show API request.
  • Zencoder can send a HTTP POST request to your application with the details.

Notification can have following parameters:

Setting

Description

notifications Be notified when a job or output is complete.
url Where you want Zencoder to send POST request to your application
format A format and content type you want notification.
headers if you need any headers for your application then you can add those in your request body under notifications
event The event that triggers a notification. Used for Instant Play.
"notifications": [{
"url": "https://bluepi.in/encode/zencn",
"format": "json",
"headers": {
"videoId": 3
}
}]

4.2.3- Output

In this section, you provide settings about encoding output. In this section we will discuss how we define request to generate Thumbnails and Video encoding.

4.2.3.1- Thumbnail Output

Zencoder traverse input video and generate thumbnail images as per your configuration provided in output section. It could be fixed time interval or you can specify time at which you want to capture screenshot of video. Let’s first discuss few parameters for thumbnail request.

Setting Default Description
thumbnails none Capture thumbnails for a given video.
label none A label to identify each set of thumbnail groups.
format png The format of the thumbnail image.
number none A number of thumbnails, evenly-spaced.
start_at_first_frame false Start generating the thumbnails starting at the first frame.
interval none Take thumbnails at an even interval, in seconds.
interval_in_frames none Take thumbnails at an even interval, in frames.
times none An array of times, in seconds, at which to grab a thumbnail.
aspect_mode preserve How to handle a thumbnail width/height that differs from the aspect ratio of the input file.
size none Thumbnail resolution as WxH.
width none The maximum width of the thumbnail (in pixels).
height none The maximum height of the thumbnail (in pixels).
base_url none A base S3, Cloud Files, GCS, FTP, FTPS, or SFTP directory URL where we’ll place the thumbnails, without a filename.
prefix frame Prefix for thumbnail filenames.
filename frame Interpolated thumbnail filename.
public false Make the output publicly readable on S3.

Let’s create a simple Output configuration where we need to create 2 different sizes of thumbnails, one with actual size of video and other of specific size.

{
"input": "s3://bluepi-original.s3.amazonaws.com/sample.mov",
"notifications": [{
"url": "https://bluepi.in/encode/zencn",
"format": "json",
"headers": {
"videoId": 3
}
}],
"outputs": [{
"thumbnails": [{
"base_url": "s3://bluepi-images.s3.amazonaws.com/videos/",
"label": "regular",
"number": 10,
"prefix": "frame",
"public": "true"
}, {
"base_url": "s3://bluepi-images.s3.amazonaws.com/videos/",
"label": "small",
"number": 10,
"size": "300x200",
"prefix": "thumb",
"public": "true"
}]
}]
}

4.2.3.2- Video Encoding Output

In this section, we will define output configuration which will encode input video and encode video as per output configuration. You can define multiple output files and zencoder will generate video files accordingly, we generally need to generate multiple files for each devices which could vary in aspect ratio, quality and bandwidth. Here I will define configuration as per my requirements, but you can change it as per yours. Let’s first discuss what different parameters we have which we can tweak to generate output  file.

Setting Default Description
type standard The type of file to output.
label none An optional label for this output.
url none A S3, Cloud Files, GCS, FTP, FTPS, SFTP, Aspera, HTTP, or RTMP URL where we’ll put the transcoded file.
base_url none A base S3, Cloud Files, GCS, FTP, FTPS, SFTP, or Aspera directory URL where we’ll put the transcoded file, without a filename.
filename none The filename of a finished file.
format The output format to use
size none The resolution of the output video (WxH, in pixels).
width none The maximum width of the output video (in pixels).
height none The maximum height of the output video (in pixels).
quality 3 Autoselect the best video bitrate to to match a target visual quality.
video_bitrate none A target video bitrate in kbps. Not necessary if you select a quality setting, unless you want to target a specific bitrate.
audio_quality 3 Autoselect the best audio bitrate to to match a target sound quality.
audio_bitrate none A target audio bitrate in kbps. Not necessary if you select a audio_quality setting, unless you want to target a specific bitrate.
audio_sample_rate none The audio sample rate, in Hz.
max_audio_sample_rate none The max audio sample rate, in Hz.

Sample output configuration as follows:

{
"label": "high",
"url": "s3://bluepi-encoded.s3.amazonaws.com/sample-high.mp4",
"audio_bitrate": 160,
"audio_sample_rate": 48000,
"height": 720,
"width": 1280,
"max_frame_rate": 30,
"video_bitrate": 5000,
"h264_level": "3.1",
"format": "mp4",
"decoder_bitrate_cap": 3000,
"decoder_buffer_size": 8000,
"h264_reference_frames": 1,
"h264_profile": "main",
"forced_keyframe_rate": "0.1",
"decimate": 2,
"public": false
}

While encoding you can add your branding to your encoded videos, for that you just need to provide a simple configuration as part of your every output item and Zencoder will put it on your encoded video automatically, it is very easy to add this. Water mark parameters are as follows:

Setting Default Description
watermarks none Add one or more watermarks to an output video.
url none The URL of a remote image file to use as a watermark.
x -10 Where to place a watermark, on the x axis.
y -10 Where to place a watermark, on the y axis.
width Scale to height, or original image width. The scaled width of a watermark.
height Scale to width, or original image height. The scaled height of a watermark.
origin content Which part of the output to base the watermark position on.
opacity 1.0 Make the watermark transparent.

Here is sample for the same.

"watermarks": [{
"x": "0%",
"y": "10%",
"url": "s3://bluepi-images.s3.amazonaws.com/videos/logo-watermark-desktop.png"
}],

Here is full request which will create multiple videos with respective watermarks.

{
"input": "s3://bluepi-original.s3.amazonaws.com/sample.mov",
"notifications": [{
"url": "https://bluepi.in/encode/zencn",
"format": "json",
"headers": {
"videoId": 3
}
}],
"outputs": [{
"access_control": [{
"permission": "FULL_CONTROL",
"grantee": "admin@bluepi.in"
}],
"label": "high",
"url": "s3://bluepi-encoded.s3.amazonaws.com/sample-high.mp4",
"audio_bitrate": 160,
"audio_sample_rate": 48000,
"height": 720,
"width": 1280,
"max_frame_rate": 30,
"video_bitrate": 5000,
"h264_level": "3.1",
"format": "mp4",
"decoder_bitrate_cap": 3000,
"decoder_buffer_size": 8000,
"h264_reference_frames": 1,
"h264_profile": "main",
"forced_keyframe_rate": "0.1",
"decimate": 2,
"watermarks": [{
"x": "95%",
"y": "-92%",
"url": "s3://bluepi-images.s3.amazonaws.com/videos/logo-watermark-desktop.png"
}],
"public": false
}, {
"access_control": [{
"permission": "FULL_CONTROL",
"grantee": "admin@bluepi.in"
}],
"label": "main",
"url": "s3://bluepi-encoded.s3.amazonaws.com/sample-main.mp4",
"audio_bitrate": 128,
"audio_sample_rate": 44100,
"height": 480,
"width": 640,
"max_frame_rate": 30,
"video_bitrate": 2000,
"h264_level": "3",
"format": "mp4",
"decoder_bitrate_cap": 2250,
"decoder_buffer_size": 6000,
"h264_reference_frames": 1,
"h264_profile": "main",
"forced_keyframe_rate": "0.1",
"decimate": 2,
"watermarks": [{
"x": "95%",
"y": "-92%",
"url": "s3://bluepi-images.s3.amazonaws.com/videos/logo-watermark-desktop.png"
}],
"public": false
}, {
"access_control": [{
"permission": "FULL_CONTROL",
"grantee": "admin@bluepi.in"
}],
"label": "3gp",
"url": "s3://bluepi-encoded.s3.amazonaws.com/sample-3gp.mp4",
"audio_bitrate": 24,
"audio_sample_rate": 16000,
"height": 240,
"width": 320,
"max_frame_rate": 15,
"video_bitrate": 192,
"h264_level": null,
"format": "mp4",
"decoder_bitrate_cap": 300,
"decoder_buffer_size": 1200,
"h264_reference_frames": 1,
"h264_profile": "main",
"forced_keyframe_rate": "0.1",
"decimate": 2,
"watermarks": [{
"x": "93%",
"y": "-90%",
"url": "s3://bluepi-images.s3.amazonaws.com/videos/logo-watermark-mobile.png"
}],
"public": false
}]
}

You can refer detailed configuration of Zencoder at Encoding Settings.

5- Conclusion

We learned in this blog that how important is video content in these days and requirements of different format/quality of videos for different devices is increasing. Zencoder is fastest videos transcoding API available in market.
In above, discussion we learned how we can prepare simple request which is required to generate different outputs, either thumbnails or videos with branding.

6- References

TAGS :

Invest in better
solutions today

Contact Us