Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Draft of file manipulation article. #4682

Merged
merged 19 commits into from Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/content/en/fundamentals/media/_toc.yaml
Expand Up @@ -17,5 +17,7 @@ toc:
section:
- title: Application Primers
path: /web/fundamentals/media/manipulating/applications
- title: Basic File Manipulation
path: /web/fundamentals/media/manipulating/files
- title: Cheat Sheet
path: /web/fundamentals/media/manipulating/cheatsheet
81 changes: 37 additions & 44 deletions src/content/en/fundamentals/media/manipulating/cheatsheet.md
Expand Up @@ -2,7 +2,7 @@ project_path: /web/_project.yaml
book_path: /web/fundamentals/_book.yaml
description: A summary of commands used to convert a raw mov file to an encrypted full HD file for web playback.

{# wf_updated_on: 2017-06-09 #}
{# wf_updated_on: 2017-06-12 #}
{# wf_published_on: 2017-06-09 #}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think '(1920 x 1980)should be(1920 x 1080)`.


# Media Manipulation Cheat Sheet {: .page-title }
Expand Down Expand Up @@ -77,14 +77,14 @@ With Shaka Packager you can combine these.

For ffmpeg, I can do this while I'm converting to mp4 or webm.

ffmpeg -i myvideo.mov -b:v 8M myvideo.mp4
ffmpeg -i myvideo.mov -vf setsar=1:1 -b:v 8M myvideo.webm
ffmpeg -i myvideo.mov -b:v 350K myvideo.mp4
ffmpeg -i myvideo.mov -vf setsar=1:1 -b:v 350K myvideo.webm

For Shaka Packager:

packager \
input=myvideo.mp4,stream=audio,output=myvideo_audio.m4a \
input=myvideo.mp4,stream=video,output=myvideo_video.mp4,bandwidth=8000000
input=myvideo.mp4,stream=video,output=myvideo_video.mp4,bandwidth=350000

### File type

Expand All @@ -102,7 +102,7 @@ ratio. Fix this with a filter (`-vf setsar=1:1`).

ffmpeg -i myvideo.mov -vf setsar=1:1 myvideo.webm

### File size
### Resolution

ffmpeg -i myvideo.webm -s 1920x1080 myvideo_1980x1020.webm

Expand All @@ -116,23 +116,7 @@ To ensure that audio and video synchronize during playback insert keyframes.
### Codec

You might have an older file whose codec you want to update. The examples below
change codecs, but do not demux. The tables sumarize the libraries used to
perform the codec conversions.

***Video***

| Extension | Codec | Library |
| --- | ----- | --- |
| mp4 | H264 | libx264 |
| webm| VP9 | libvpx-vp9 |

***Audio***

| Extension | Codec | Library |
| --- | ----- | --- |
| mp4 | aac | aac |
| webm| vorbis | libvorbis |
| | opus | libopus |
change codecs, but do not demux.

***mp4/H.264***

Expand All @@ -151,6 +135,25 @@ perform the codec conversions.
ffmpeg -i myvideo.webm -v:c copy -v:a libvorbis myvideo.webm
ffmpeg -i myvideo.webm -v:c copy -v:a libopus myvideo.webm

The tables sumarize the libraries used in ffmpeg to perform the codec
conversions for webm and mp4 files. These are the formats used for DASH and HLS
respectively.

***Video***

| Extension | Codec | Library |
| --- | ----- | --- |
| mp4 | H264 | libx264 |
| webm| VP9 | libvpx-vp9 |

***Audio***

| Extension | Codec | Library |
| --- | ----- | --- |
| mp4 | aac | aac |
| webm| vorbis | libvorbis |
| | opus | libopus |

## Package

### DASH/MPD
Expand Down Expand Up @@ -180,7 +183,7 @@ for live streaming and video on demand for the web.
You can use the same method to create a key for both DASH and HLS. Do this using
openssl. The following will create a key made of 16 hex values.

openssl rand 16 > media.key
openssl rand -out media.key 16

This command creates a file with white space and new line characters, which are
not allowed by Shaka Packager. You'll need to open the key file and manually
Expand All @@ -191,17 +194,12 @@ remove all whitespace including the final carriage return.
For the `-key` flag use the key created earlier and stored in the media.key
file. However, when entering it on the command line, be sure you've removed its
whitespace. For the `-key_id` flag repeat the key value.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key_id is really an identifier that uniquely identifies the key. It can usually be found in the manifests and media containers in plain text/hex.

Some applications concatenate key_id and key and store them together, e.g. Apple's segmenter tool. This gives an impression that key_id is part of the key, but it is actually not.

The size of key needs to be 16 bytes because we are using AES-128 (128 bits, 16 bytes) for CENC and SAMPLE-AES.

The requirement of key-id being 16 bytes comes from CENC spec (23001-7) which requires key-id (KID) to be 16 bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It can usually be found in the manifests and media containers in plain text/hex." What manifests and media containers?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought you meant. But I haven't created the MPD yet. Is there some place else I can get it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find it in CENC spec (23001-7:2016).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full text of the spec in $118. Can you please just give me the answer?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what answer you need. I think you can just say:

key_id is an identifier that uniquely identifies the key.

If you want, you can mention that:

It is available in packager outputs in plaintext. It will be used by the player / content decryption module to select the right key to decrypt the content.

Let me know if you need anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I'm encrypting in but not doing DASH? Is there some other way to get the key_id?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier, it is also available in tenc box for fMP4.


> **Note:** Technically, the key ID is supposed to be either the first 8 OR the
> first 16 hex digits of the key. Since packager requires the key to be 16
> digits and does not allow a 32 digit key, both flags use the same value.


packager \
input=myvideo.mp4,stream=audio,output=glocka.m4a \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--enable_fixed_key_decryption is not needed below.

'-key_id INSERT_KEY_HERE' should be '-key_id INSERT_KEY_ID_HERE'

input=myvideo.mp4,stream=video,output=glockv.mp4 \
--enable_fixed_key_encryption --enable_fixed_key_decryption \
-key INSERT_KEY_HERE -key_id INSERT_KEY_HERE \
--enable_fixed_key_encryption \
-key INSERT_KEY_HERE -key_id INSERT_KEY_ID_HERE \

### Create a key information file

Expand Down Expand Up @@ -230,17 +228,12 @@ This command will accept a key with either 16 or 32 characters.

## Widevine Encryption

Everything in this command except the name of your files and the `--content_id`
flag should be copied exactly from the example. The `--content_id` is 16 or 32
random hex digits. Use the keys provided here instead of your own. (This is how
Widevine works.)

packager \
input=glocken.mp4,stream=video,output=enc_glocken.mp4 \
input=myvide.mp4,stream=audio,output=enc_myaudio.m4a \
input=glocken.mp4,stream=video,output=enc_video.mp4 \
input=glocken.mp4,stream=audio,output=enc_audio.m4a \
--enable_widevine_encryption \
--key_server_url "https://license.uat.widevine.com/cenc/getcontentkey/widevine_test" \
--content_id "fd385d9f9a14bb09" --signer "widevine_test" \
--content_id "Hec_converted_random_ID" --signer "widevine_test" \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hec/Hex/

I'd also replace random with unique.

--aes_signing_key "1ae8ccd0e7985cc0b6203a55855a1034afc252980e970ca90e5202689f947ab9" \
--aes_signing_iv "d58ce954203b7c9a9a9d467f59839249"

Expand All @@ -264,7 +257,7 @@ Not all steps are possible with Shaka Packager, so I'll use ffmpeg when I need t
including the final carriage return.

```
openssl rand 16 > media.key
openssl rand -out media.key 16
```

3. Demux the audio and video, encrypt the new files, and output a media
Expand All @@ -276,7 +269,7 @@ Not all steps are possible with Shaka Packager, so I'll use ffmpeg when I need t
``` input=myvideo.webm,stream=video,output=myvideo_video.webm \```<br/>
``` input=myvideo.webm,stream=audio,output=myvideo_audio.webm \```<br/>
``` --enable_fixed_key_encryption --enable_fixed_key_decryption \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_HERE \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_ID_HERE \```<br/>
``` --mpd_output myvideo_vod.mpd```

### DASH/mp4 with Shaka Packager
Expand All @@ -300,7 +293,7 @@ Not all steps are possible with Shaka Packager, so I'll use ffmpeg when I need t
including the final carriage return.

```
openssl rand 16 > media.key
openssl rand -out media.key 16
```

3. Demux the audio and video, encrypt the new files, and output a media
Expand All @@ -312,7 +305,7 @@ Not all steps are possible with Shaka Packager, so I'll use ffmpeg when I need t
``` input=mymovie.mp4,stream=audio,output=myaudio.m4a \```<br/>
``` input=mymovie.mp4,stream=video,output=myvideo.mp4 \```<br/>
``` --enable_fixed_key_encryption --enable_fixed_key_decryption \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_HERE \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_ID_HERE \```<br/>
``` --mpd_output myvideo_vod.mpd```

### Widevine
Expand Down Expand Up @@ -357,7 +350,7 @@ ffmpeg when I need to.
including the final carriage return.

```
openssl rand 16 > media.key
openssl rand -out media.key 16
```

3. Create a key information file
Expand All @@ -370,4 +363,4 @@ ffmpeg when I need to.
``` --hls_master_playlist_output="master_playlist.m3u8" \```<br/>
``` --hls_base_url="http://localhost:1000/" \```<br/>
``` --enable_fixed_key_encryption --enable_fixed_key_decryption \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_HERE \```<br/>
``` -key INSERT_KEY_HERE -key_id INSERT_KEY_ID_HERE \```<br/>