Draft of file manipulation article. #4682
Changes from 3 commits
fd49453
39197b5
02d7e22
7d4e967
3a29edb
36d4fad
539a55d
dafa15a
1a1caa3
d447a37
f0724e9
1462717
ac40e56
2712ebc
cc9f77f
57371b8
b74bd4f
bd1ecad
d5db8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 #} | ||
|
||
# Media Manipulation Cheat Sheet {: .page-title } | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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*** | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Some applications concatenate 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, DASH MPD(cenc:default_KID, see https://github.com/google/shaka-packager/blob/master/packager/app/test/testdata/bear-640x360-av-cenc-golden.mpd), fmp4 (in tenc box). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can find it in CENC spec (23001-7:2016). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what answer you need. I think you can just say:
If you want, you can mention that:
Let me know if you need anything else. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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/> |
There was a problem hiding this comment.
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)`.