2016-07-01 21:49:46 +00:00
# ![Shaka Packager](docs/shaka-packager.png)
2016-05-17 00:41:02 +00:00
[![Build Status ](https://travis-ci.org/google/shaka-packager.svg?branch=master )](https://travis-ci.org/google/shaka-packager)
2016-02-18 18:48:46 +00:00
2016-07-01 21:49:46 +00:00
Media packaging SDK intended for C++ programmers writing DASH/HLS packager applications with common encryption support, Widevine DRM support, Live, and Video-On-Demand.
2014-04-17 22:51:39 +00:00
2016-07-01 21:49:46 +00:00
This document provides the information needed to create a DASH/HLS packager that is able to remux and encrypt a video into fragmented ISO BMFF format with common encryption (CENC) support. The DASH/HLS packaging API is also designed in such a way for easy extension to more source and destination formats.
2014-04-17 22:51:39 +00:00
2016-01-12 00:31:45 +00:00
Current supported codecs:
| Codecs | ISO-BMFF | WebM | MPEG2-TS | WVM |
|:-----------------:|:------------:|:------------:|:------------:|:-----------:|
2016-06-14 19:06:05 +00:00
| H264 (AVC) | I / O | - | I / O | I |
2016-03-31 19:48:16 +00:00
| H265 (HEVC) | I / O | - | I | - |
2016-07-01 21:49:46 +00:00
| VP8 | *I / O* | I / O | - | - |
| VP9 | *I / O* | I / O | - | - |
2016-06-14 19:06:05 +00:00
| AAC | I / O | - | I / O | I |
2016-03-31 21:06:19 +00:00
| Dolby AC3/EAC3 | I / O | - | - | - |
2016-01-12 00:31:45 +00:00
| DTS | I / O | - | - | - |
2016-07-01 21:49:46 +00:00
| Opus | *I / O* | I / O | - | - |
2016-01-12 00:31:45 +00:00
| Vorbis | - | I / O | - | - |
** I for input and O for output.
2016-07-01 21:49:46 +00:00
** VP8/VP9/Opus support in ISO-BMFF is experimental.
2016-01-12 00:31:45 +00:00
2016-05-17 00:41:02 +00:00
Right now this project is supported directly on Linux and MacOSX platforms only. One option to run shaka-packager on other platforms is using [docker] (#Using docker for testing /development).
2016-01-12 00:31:45 +00:00
2015-03-24 22:16:16 +00:00
# Mailing list #
2016-05-17 00:41:02 +00:00
We have a [public mailing list ](https://groups.google.com/forum/#!forum/shaka-packager-users ) for discussion and announcements. To receive notifications about new versions, please join the list. You can also use the list to ask questions or discuss Shaka Packager developments.
2015-03-24 22:16:16 +00:00
2014-04-17 22:51:39 +00:00
# Setting up for development #
2016-05-17 00:41:02 +00:00
1. Packager source is managed by Git at https://www.github.com/google/shaka-packager. We use gclient tool from Chromium to manage third party libraries. You will need Git (v1.7.5 or above) installed on your machine to access the source code.
2014-04-17 22:51:39 +00:00
2014-06-27 19:07:43 +00:00
2. Install Chromium depot tools which contains gclient and ninja
See http://www.chromium.org/developers/how-tos/install-depot-tools for details.
2014-04-17 22:51:39 +00:00
3. Get the source
2014-06-27 19:07:43 +00:00
```Shell
2016-05-17 00:41:02 +00:00
mkdir shaka_packager
cd shaka_packager
gclient config https://www.github.com/google/shaka-packager.git --name=src
2014-06-27 19:07:43 +00:00
gclient sync
```
2015-09-30 17:19:10 +00:00
To sync to a particular commit or version, use 'gclient sync -r \<revision\>', e.g.
```Shell
# Sync to commit 4cb5326355e1559d60b46167740e04624d0d2f51
gclient sync -r 4cb5326355e1559d60b46167740e04624d0d2f51
# Sync to version 1.2.0
gclient sync -r v1.2.0
```
2014-04-17 22:51:39 +00:00
4. Build
2014-06-27 19:07:43 +00:00
We use ninja, which is much faster than make, to build our code:
```Shell
cd src
ninja -C out/{Debug,Release} [Module]
```
Module is optional. If not specified, build all, e.g.
```Shell
ninja -C out/Debug # build all modules in Debug mode
ninja -C out/Release # build all modules in Release mode
2014-07-16 23:41:54 +00:00
ninja -C out/Release mp4 # build mp4 module in Release mode
2014-06-27 19:07:43 +00:00
```
Refer to ninja manual for details.
2014-10-01 20:44:41 +00:00
We also provide a mechanism to change build configurations, for example, developers can change build system to “make” by overriding *GYP_GENERATORS* .
2014-06-27 19:07:43 +00:00
```Shell
2014-10-01 20:44:41 +00:00
GYP_GENERATORS='make' gclient runhooks
2014-06-27 19:07:43 +00:00
```
Another example, developers can also enable clang by overriding *GYP_DEFINE* .
```Shell
2014-10-01 20:44:41 +00:00
GYP_DEFINES='clang=1' gclient runhooks
2014-06-27 19:07:43 +00:00
```
5. Updating the code
Update your current branch with *git pull* followed by *gclient sync* . Note that if you are not on a branch, *git pull* will not work, and you will need to use *git fetch* instead.
6. Contributing
2016-05-17 00:41:02 +00:00
See https://github.com/google/shaka-packager/blob/master/CONTRIBUTING.md for details.
2014-06-27 19:07:43 +00:00
2015-07-23 01:49:26 +00:00
2015-09-30 17:19:10 +00:00
# Using docker for testing / development #
2015-07-23 01:49:26 +00:00
2015-09-30 17:19:10 +00:00
[Docker ](https://www.docker.com/whatisdocker ) is a tool that can package an application and its dependencies in a virtual container to run on different host operating systems.
1. Install [Docker ](https://docs.docker.com/installation/ ).
2015-07-23 01:49:26 +00:00
2016-03-31 21:06:19 +00:00
2. Pull prebuilt image from Dockerhub or build an image locally
2015-07-23 01:49:26 +00:00
2016-03-31 21:06:19 +00:00
2.a. Pull prebuilt image from Dockerhub
```Shell
2016-05-17 00:41:02 +00:00
docker pull google/shaka-packager
2016-03-31 21:06:19 +00:00
```
2.b. Build an image locally
```Shell
2016-05-17 00:41:02 +00:00
docker build -t google/shaka-packager github.com/google/shaka-packager.git
2016-03-31 21:06:19 +00:00
```
2015-07-23 01:49:26 +00:00
3. Run the container (`your_media_path` should be your media folder)
```Shell
2016-05-17 00:41:02 +00:00
docker run -v /your_media_path/:/media -it --rm google/shaka-packager
2015-07-23 01:49:26 +00:00
```
2015-09-30 17:19:10 +00:00
4. Testing
2015-07-23 01:49:26 +00:00
```Shell
2015-09-30 17:19:10 +00:00
# Make sure you run step 3 and you're inside the container.
cd /media
2015-07-23 01:49:26 +00:00
# VOD: mp4 --> dash
2015-09-30 17:19:10 +00:00
packager input=/media/example.mp4,stream=audio,output=audio.mp4 \
input=/media/example.mp4,stream=video,output=video.mp4 \
--profile on-demand --mpd_output example.mpd
2015-07-23 01:49:26 +00:00
2015-09-30 17:19:10 +00:00
# Leave the container.
2015-07-23 01:49:26 +00:00
exit
```
2015-09-30 17:19:10 +00:00
Outputs are available in your media folder `your_media_path` .
2014-04-17 22:51:39 +00:00
2016-01-12 00:31:45 +00:00
# Design overview #
2014-04-17 22:51:39 +00:00
Major modules are described below:
2014-10-10 19:10:03 +00:00
Demuxer is responsible for extracting elementary stream samples from a multimedia file, e.g. an ISO BMFF file. The demuxed streams can be fed into a muxer to generate multimedia files. An optional KeySource can be provided to Demuxer to decrypt CENC and WVM source content.
2014-04-17 22:51:39 +00:00
2014-06-27 19:07:43 +00:00
Demuxer reads from source through the File interface. A concrete LocalFile class is already implemented. The users may also implement their own File class if they want to read/write using a different kinds of protocol, e.g. network storage, http etc.
2014-04-17 22:51:39 +00:00
2014-08-20 23:51:15 +00:00
Muxer is responsible for taking elementary stream samples and producing media segments. An optional KeySource can be provided to Muxer to generate encrypted outputs. Muxer writes to output using the same File interface as Demuxer.
2014-04-17 22:51:39 +00:00
Demuxer and Muxer are connected using MediaStream. MediaStream wraps the elementary streams and is responsible for the interaction between Demuxer and Muxer. A demuxer can transmits multiple MediaStreams; similarly, A muxer is able to accept and mux multiple MediaStreams, not necessarily from the same Demuxer.
2014-06-27 19:07:43 +00:00
MpdBuilder is responsible for the creation of Media Presentation Description as specified in ISO/IEC 23009-1 DASH MPD spec.
2014-04-17 22:51:39 +00:00
2016-05-17 00:41:02 +00:00
Refer to [Design ](docs/design.md ), [API ](https://google.github.io/shaka-packager/docs ) for details.
2014-04-17 22:51:39 +00:00
2016-01-12 00:31:45 +00:00
# DASH-IF IOP Compliance #
2015-09-30 17:19:10 +00:00
We try out best to be compliant to [Guidelines for Implementation: DASH-IF Interoperability Points ](http://dashif.org/wp-content/uploads/2015/04/DASH-IF-IOP-v3.0.pdf ).
We are already compliant to most of the requirements specified by the document, with two exceptions:
- ContentProtection elements are still put under Representation element instead of AdaptationSet element;
- Representations encrypted with different keys are still put under the same AdaptationSet.
We created a flag '--generate_dash_if_iop_compliant_mpd', if enabled,
- ContentProtection elements will be moved under AdaptationSet;
- Representations encrypted with different keys will be put under different AdaptationSets, grouped by `@group` attribute.
Users can enable the flag '--generate_dash_if_iop_compliant_mpd' to have these features. This flag will be enabled by default in a future release.
Please feel free to file a bug or feature request if there are any incompatibilities with DASH-IF IOP or other standards / specifications.
2016-01-12 00:31:45 +00:00
# Driver Program Sample Usage #
2014-04-17 22:51:39 +00:00
2014-06-27 19:07:43 +00:00
Sample driver programs **packager** and **mpd_generator** are written using the SDK.
Some sample usages:
2014-04-17 22:51:39 +00:00
Run the program without arguments will display the help page with the list of command line arguments:
```Shell
2014-06-27 19:07:43 +00:00
packager
2014-04-17 22:51:39 +00:00
```
Dump stream info:
```Shell
2014-06-27 19:07:43 +00:00
packager input=sintel.mp4 --dump_stream_info
2014-04-17 22:51:39 +00:00
```
Demux audio from the input and generate a fragmented mp4:
```Shell
2014-06-27 19:07:43 +00:00
packager input=sintel.mp4,stream=audio,output=fragmented_sintel.mp4
2014-04-17 22:51:39 +00:00
```
2014-06-27 19:07:43 +00:00
Demux streams from the input and generates a mpd with on-demand profile along with fragmented mp4:
2014-04-17 22:51:39 +00:00
```Shell
2014-06-27 19:07:43 +00:00
packager \
input=sintel.mp4,stream=audio,output=sintel_audio.mp4 \
input=sintel.mp4,stream=video,output=sintel_video.mp4 \
--profile on-demand \
--mpd_output sintel_vod.mpd
2014-04-17 22:51:39 +00:00
```
2016-01-12 00:31:45 +00:00
Includes a subtitle input from webvtt:
```Shell
packager \
input=sintel.mp4,stream=audio,output=sintel_audio.mp4 \
input=sintel.mp4,stream=video,output=sintel_video.mp4 \
input=sintel_english_input.vtt,stream=text,output=sintel_english.vtt \
--profile on-demand \
--mpd_output sintel_vod.mpd
```
2014-06-27 19:07:43 +00:00
You may also generate mpd with live profile. Here is an example with IPTV input streams:
2014-04-17 22:51:39 +00:00
```Shell
2014-06-27 19:07:43 +00:00
packager \
'input=udp://224.1.1.5:5003,stream=audio,init_segment=live-audio.mp4,segment_template=live-audio-$Number$.mp4,bandwidth=130000' \
'input=udp://224.1.1.5:5003,stream=video,init_segment=live-video-sd.mp4,segment_template=live-video-sd-$Number$.mp4,bandwidth=2000000' \
'input=udp://224.1.1.5:5002,stream=video,init_segment=live-video-hd.mp4,segment_template=live-video-hd-$Number$.mp4,bandwidth=5000000' \
--profile live \
--mpd_output live.mpd
```
2014-10-10 19:10:03 +00:00
Demux video from the input and generate an encrypted fragmented mp4 using Widevine encryption with RSA signing key file *widevine_test_private.der* :
2014-06-27 19:07:43 +00:00
```Shell
packager input=sintel.mp4,stream=video,output=encrypted_sintel.mp4 \
2014-04-17 22:51:39 +00:00
--enable_widevine_encryption \
2014-06-27 19:07:43 +00:00
--key_server_url "https://license.uat.widevine.com/cenc/getcontentkey/widevine_test" \
2014-11-06 23:13:35 +00:00
--content_id "3031323334353637" \
2014-04-17 22:51:39 +00:00
--signer "widevine_test" \
--rsa_signing_key_path "widevine_test_private.der"
```
2014-06-27 19:07:43 +00:00
The program also supports AES signing. Here is an example with encryption key rotates every 1800 seconds:
2014-04-17 22:51:39 +00:00
```Shell
2015-09-14 23:47:28 +00:00
packager \
'input=udp://224.1.1.5:5003,stream=audio,init_segment=live-audio.mp4,segment_template=live-audio-$Number$.mp4,bandwidth=130000' \
'input=udp://224.1.1.5:5003,stream=video,init_segment=live-video-sd.mp4,segment_template=live-video-sd-$Number$.mp4,bandwidth=2000000' \
'input=udp://224.1.1.5:5002,stream=video,init_segment=live-video-hd.mp4,segment_template=live-video-hd-$Number$.mp4,bandwidth=5000000' \
--profile live \
--mpd_output live.mpd \
2014-04-17 22:51:39 +00:00
--enable_widevine_encryption \
2014-06-27 19:07:43 +00:00
--key_server_url "https://license.uat.widevine.com/cenc/getcontentkey/widevine_test" \
2014-11-06 23:13:35 +00:00
--content_id "3031323334353637" \
2014-04-17 22:51:39 +00:00
--signer "widevine_test" \
--aes_signing_key "1ae8ccd0e7985cc0b6203a55855a1034afc252980e970ca90e5202689f947ab9" \
2014-06-27 19:07:43 +00:00
--aes_signing_iv "d58ce954203b7c9a9a9d467f59839249" \
--crypto_period_duration 1800
2014-04-17 22:51:39 +00:00
```
2015-09-14 23:47:28 +00:00
Note that key rotation is only supported for live profile.
2014-04-17 22:51:39 +00:00
2014-10-10 19:10:03 +00:00
Demux and decrypt video from a WVM container, and generate encrypted fragmented mp4 using Widevine encryption with RSA signing key file *widevine_test_private.der* :
```Shell
packager input=sintel.wvm,stream=video,output=encrypted_sintel.mp4 \
--enable_widevine_decryption \
--enable_widevine_encryption \
--key_server_url "https://license.uat.widevine.com/cenc/getcontentkey/widevine_test" \
2014-11-06 23:13:35 +00:00
--content_id "3031323334353637" \
2014-10-10 19:10:03 +00:00
--signer "widevine_test" \
--rsa_signing_key_path "widevine_test_private.der"
```
2014-06-27 19:07:43 +00:00
The program can be told to generate MediaInfo files, which can be fed to **mpd_generate** to generate the mpd file.
2014-04-17 22:51:39 +00:00
```Shell
2014-06-27 19:07:43 +00:00
packager \
input=sintel.mp4,stream=video,output=sintel_video.mp4 \
input=sintel.mp4,stream=audio,output=sintel_audio.mp4 \
--output_media_info
2014-04-17 22:51:39 +00:00
mpd_generator \
2014-06-27 19:07:43 +00:00
--input "sintel_video.mp4.media_info,sintel_audio.mp4.media_info" \
--output "sintel.mpd"
2014-04-17 22:51:39 +00:00
```
2016-06-14 19:06:05 +00:00
Output MPEG2-TS video.
```Shell
packager \
2016-07-01 21:49:46 +00:00
'input=bear-1280x720.mp4,stream=video,segment_template=bear$Number$.ts'
2016-06-14 19:06:05 +00:00
```
Output HLS playlists with MPEG2-TS video. The following outputs a Master
Playlist as `master.m3u8` . And the Media Playlist for the video as
2016-07-01 21:49:46 +00:00
`playlist.m3u8` . The optional `--hls_base_url` specifies the prefix for the
2016-06-14 19:06:05 +00:00
generated TS segments.
```Shell
packager \
2016-07-01 21:49:46 +00:00
'input=bear-1280x720.mp4,stream=video,segment_template=bear$Number$.ts,playlist_name=playlist.m3u8' \
2016-06-14 19:06:05 +00:00
--single_segment=false \
--hls_master_playlist_output="master.m3u8" \
--hls_base_url="http://localhost:10000/"
```
For audio Media Playlists, the name and group for EXT-X-MEDIA tag must be
specified.
```Shell
packager \
2016-07-01 21:49:46 +00:00
'input=input.mp4,stream=video,segment_template=output$Number$.ts,playlist_name=video_playlist.m3u8' \
'input=input.mp4,stream=audio,segment_template=output_audio$Number$.ts,playlist_name=audio_playlist.m3u8,hls_group_id=audio,hls_name=ENGLISH' \
2016-06-14 19:06:05 +00:00
--single_segment=false \
--hls_master_playlist_output="master_playlist.m3u8" \
--hls_base_url="http://localhost:10000/"
```