I am trying to play from local storage an encrypted video using ExoPlayer. The command used to encrypt the video using FFMPEG is as follows:
-i /storage/emulated/0/Download/20210125_193031.mp4 -vcodec copy -acodec copy -c:v libx264 -encryption_scheme cenc-aes-ctr -encryption_key b42ca3172ee4e69bf51848a59db9cd13 -encryption_kid 09e367028f33436ca5dd60ffe6671e70 /storage/emulated/0/Download/out_enc.mp4
Here it is the sourcecode of my player:
public class PlayerActivity extends AppCompatActivity { private SimpleExoPlayer player; private DefaultDrmSessionManager drmSessionManager; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); // Build the media item. PlayerView playerView = findViewById(R.id.video_view); player = new SimpleExoPlayer.Builder(this).build(); playerView.setPlayer(player); //player.prepare(); //FFMPEG command: -i /storage/emulated/0/Download/20210125_193031.mp4 -vf scale=-1:720 -c:v libx264 -encryption_scheme cenc-aes-ctr -encryption_key b42ca3172ee4e69bf51848a59db9cd13 -encryption_kid 09e367028f33436ca5dd60ffe6671e70 /storage/emulated/0/Download/out_enc.mp4 //base 64 keys generated from: https://www.base64encode.org/ //playVideo("/storage/emulated/0/Download/out_enc.mp4", "MDllMzY3MDI4ZjMzNDM2Y2E1ZGQ2MGZmZTY2NzFlNzA=", "YjQyY2EzMTcyZWU0ZTY5YmY1MTg0OGE1OWRiOWNkMTM="); playVideo("/storage/emulated/0/Download/out_enc.mp4", "CeNnAo8zQ2yl3WD/5mcecA", "tCyjFy7k5pv1GEilnbnNEw"); } private void playVideo(String url, String keyID, String keyValue) { try { drmSessionManager = buildDrmSessionManager(Util.getDrmUuid(C.CLEARKEY_UUID.toString()), true, keyID, keyValue ); } catch (Exception e) { e.printStackTrace(); } player.setMediaSource(buildDashMediaSource(Uri.parse(url))); player.prepare(); player.setPlayWhenReady(true); } private MediaSource buildDashMediaSource(Uri uri) { DefaultDataSourceFactory dashChunkSourceFactory = new DefaultDataSourceFactory(this, "agent"); return new ProgressiveMediaSource.Factory(dashChunkSourceFactory) .setDrmSessionManager(drmSessionManager) .createMediaSource(uri); } private DefaultDrmSessionManager buildDrmSessionManager(UUID uuid, Boolean multiSession, String id, String value) { /* String base64Id = Base64.encodeToString(id.getBytes(), Base64.DEFAULT); String base64Value = Base64.encodeToString(value.getBytes(), Base64.DEFAULT);*/ String keyString = "{\"keys\":[{\"kty\":\"oct\",\"k\":\""+value+"\",\"kid\":\""+id+"\"}],\"type\":\"temporary\"}";; LocalMediaDrmCallback drmCallback = new LocalMediaDrmCallback(keyString.getBytes()); FrameworkMediaDrm mediaDrm = null; try { mediaDrm = FrameworkMediaDrm.newInstance(uuid); } catch (UnsupportedDrmException e) { e.printStackTrace(); } return new DefaultDrmSessionManager(uuid, mediaDrm, drmCallback, null, multiSession); } @Override protected void onDestroy() { player.release(); super.onDestroy(); } Here it is the link for the encrypted video. The main issue: the video is playing but is not decrypted. What am I missing?
https://stackoverflow.com/questions/65950956/play-aes-encrypted-video-in-exoplayer-offline January 29, 2021 at 04:19PM
没有评论:
发表评论