shaka-project / shaka-streamer

A simple config-file based approach to preparing streaming media, based on FFmpeg and Shaka Packager.
https://shaka-project.github.io/shaka-streamer/
Apache License 2.0
198 stars 62 forks source link

Add FairPlay hls_key_uri support to encryption config #76

Open mardu opened 3 years ago

mardu commented 3 years ago

At the moment shaka-packager has a --hls_key_uri option for FairPlay. If it is not set, it will be generated from key_id like this:

  if (IsFairPlaySystemId(system_id)) {
    std::string key_uri = hls_params().key_uri;
    if (key_uri.empty()) {
      // Use key_id as the key_uri. The player needs to have custom logic to
      // convert it to the actual key uri.
      std::string key_uri_data = VectorToString(key_id);
      key_uri = Base64EncodeData(kUriFairPlayPrefix, key_uri_data);
    }

    // FairPlay defines IV to be carried with the key, not the playlist.
    const std::vector<uint8_t> empty_iv;
    NotifyEncryptionToMediaPlaylist(encryption_method, key_uri, empty_key_id,
                                    empty_iv, "com.apple.streamingkeydelivery",
                                    "1", media_playlist.get());
    return true;
  }

This however need custom player logic as noted in the comment which i am trying to avoid.

It would make sense to add hls_key_uri option to encryption config as a parameter. If i hardcode hls_key_uri as skd://XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX in packager_node.py then FairPlay with Shaka Player demo starts playing the video correctly. Maybe there is another way to pass the correct URI to playlist? The pipeline configuration looks like this:

encryption:
  enable: True
  encryption_mode: raw
  keys:
    - key_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  iv: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  protection_systems:
    - FairPlay
  protection_scheme: cbcs