1

我已经尝试过播放未加密的破折号流,在 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 文件-----------

<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

文件的文件夹结构

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

http://localhost:8085/test23/output u .mpd --> 非加密 url

未加密的 url 与 exoplayer 代码完美配合,即使 2 小时的视频也没有搜索时间

安卓的代码

SimpleExoPlayerView 组件

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

爪哇代码

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();
    }
}

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

4

0 回答 0