如何在exoplayer2中播放加密的破折号块

时间:2018-11-02 22:25:01

标签: encryption exoplayer exoplayer2.x mp4box

我已经尝试过未加密的破折号流在exoplayer2中的任何问题下都能正常工作..

但是我不知道如何解密流以及在没有加密的情况下完美无瑕。

我还没有尝试过使用exoplayer解密代码来建议这样做。

我已经使用ffmpeg和mp4box

intercept.mp4->是原始的源视频文件

//-视频和音频分离和解析速度脚本

ffmpeg -i intercept.mp4 -s 320x180 -c:v libx264 -b:v 500k -g 90 -an INVI_320x180_500k.mp4 & 
ffmpeg -i intercept.mp4 -c:a aac -b:a 128k -vn INAU_128k.mp4 &

// ---------------- AES CTR模式下具有键和IV的XML文件----------- < / p>

<GPACDRM type="CENC *AES-CTR*">
  <DRMInfo type="pssh" version="1">
    <BS ID128="1077efecc0b24d02ace33c1e52e2fb4b"/>
    <BS bits="32" value="1"/>
    <BS ID128="cd7eb9ff88f34caeb06185b00024e4c2"/>
  </DRMInfo>
  <CrypTrack IV_size="8" first_IV="*0xbb5738fe08f11341*" isEncrypted="1" saiSavedBox="senc" trackID="1">
    <key KID="0xcd7eb9ff88f34caeb06185b00024e4c2" value="*0x63cb5f7184dd4b689a5c5ff11ee6a328*"/>
  </CrypTrack>
</GPACDRM>

//-加密脚本

MP4Box -crypt drm.xml INVI_320x180_500k.mp4 -out INVI_320x180_500k_ENCRYPTED.mp4
MP4Box -crypt drm.xml INAU_128k.mp4 -out INAU_128k_ENCRYPTED.mp4

//-解密脚本-

MP4Box -decrypt drm.xml INVI_320x180_500k_ENCRYPTED.mp4 -out INVI_320x180_500k_DEENCRYPTED.mp4
MP4Box -decrypt drm.xml INAU_128k_ENCRYPTED.mp4 -out INAU_128k_DEENCRYPTED.mp4

//-加密段的最高级-

MP4Box -dash 10000 -segment-name "outputE/outputseg-%s" -url-template -bs-switching no -out outpute.mpd -rap INVI_320x180_500k_ENCRYPTED.mp4 INAU_128k_ENCRYPTED.mp4

//-非加密段的最高级-

MP4Box -dash 10000 -segment-name "outputU/outputseg-%s" -url-template -bs-switching no -out outputu.mpd -rap INVI_320x180_500k.mp4 INAU_128k.mp4

Folder structure of file

http://localhost:8085/test23/output e .mpd->加密的网址

http://localhost:8085/test23/output u .mpd->未加密的网址

未经加密的url与exoplayer代码完美结合,即使2小时视频也没有寻道时间

andriod的代码

SimpleExoPlayerView组件

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
    android:id="@+id/player_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

java代码

public class PlayMpd extends AppCompatActivity
{
    private String VIDEO_URI ;
            //"http://weit.in/sidd/int/manifest.mpd";
    private SimpleExoPlayer player;
    private SimpleExoPlayerView simpleExoPlayerView;
    private Handler mainHandler;
    private TrackSelection.Factory videoTrackSelectionFactory;
    private TrackSelector trackSelector;
    private LoadControl loadControl;
    private DataSource.Factory dataSourceFactory;
    private Aes128DataSource aes128DataSource;
    private MediaSource videoSource;
    private Uri uri;
    private String userAgent;
    private static final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    private Cipher cipher;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); // this will secure app with taking screenshot and screen recording
        setContentView(R.layout.activity_play_mpd);
        //Intent url = getIntent();
        //VIDEO_URI = url.getStringExtra("url").toString();
        VIDEO_URI = "encrypted or decrypted utl of mpd file";
        simpleExoPlayerView = findViewById(R.id.player_view);
        userAgent = Util.getUserAgent(this,"SimpleDashExoPlayer");
        createPlayer();
        attachPlayerView();
        preparePlayer();

    }
    // Create TrackSelection Factory, Track Selector, Handler, Load Control, and ExoPlayer Instance
    public void createPlayer(){
        mainHandler = new Handler();
        videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        //videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        loadControl = new DefaultLoadControl();
        player = ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl);
    }
    // Set player to SimpleExoPlayerView
    public void attachPlayerView(){
        simpleExoPlayerView.setPlayer(player);
    }
    // Build Data Source Factory, Dash Media Source, and Prepare player using videoSource
    public void preparePlayer(){
        uriParse();
        dataSourceFactory = buildDataSourceFactory(bandwidthMeter);
        videoSource = new DashMediaSource(uri,buildDataSourceFactory(null),
                new DefaultDashChunkSource.Factory(dataSourceFactory),mainHandler,null);
        player.prepare(videoSource);
    }
    // Parse VIDEO_URI and Save at uri variable
    public void uriParse(){
        uri = Uri.parse(VIDEO_URI);
    }
    // Build Data Source Factory using DefaultBandwidthMeter and HttpDataSource.Factory
    private DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
        return new DefaultDataSourceFactory(this, bandwidthMeter, buildHttpDataSourceFactory(bandwidthMeter));
    }
    // Build Http Data Source Factory using DefaultBandwidthMeter
    private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
        return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
    }
    // Activity onStop, player must be release because of memory saving
    @Override
    public void onStop(){
        super.onStop();
        player.release();
    }
}

需要建议解密片段并直接播放。

0 个答案:

没有答案