You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用DirectShow从内存播放自定义加密的视频?

问题:借助DirectShow从内存播放加密视频

背景

我之前用RijndaelManaged加密了视频文件来保护内容,加密代码如下:

private void EncryptFile(string inputFile, string outputFile) { 
    try { 
        string password = @"MyKey123"; // Your Key Here 
        UnicodeEncoding UE = new UnicodeEncoding(); 
        byte[] key = UE.GetBytes(password); 
        string cryptFile = outputFile; 
        FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create); 
        RijndaelManaged RMCrypto = new RijndaelManaged(); 
        CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write); 
        FileStream fsIn = new FileStream(inputFile, FileMode.Open); 
        int data; 
        while ((data = fsIn.ReadByte()) != -1) cs.WriteByte((byte)data); 
        fsIn.Close(); 
        cs.Close(); 
        fsCrypt.Close(); 
    } catch { 
        MessageBox.Show("Encryption failed!", "Error"); 
    } 
}

现在我希望直接从内存中播放这些加密视频,调研后知道需要用DirectShow实现内存播放,但不清楚怎么结合我现有的解密代码来完成这个需求,我的解密代码如下:

private void DecryptFile(string inputFile, string outputFile) { 
    string password = @"MyKey123"; // Your Key Here 
    UnicodeEncoding UE = new UnicodeEncoding(); 
    byte[] key = UE.GetBytes(password); 
    FileStream fsCrypt = new FileStream(inputFile, FileMode.Open); 
    RijndaelManaged RMCrypto = new RijndaelManaged(); 
    CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateDecryptor(key, key), CryptoStreamMode.Read); 
    FileStream fsOut = new FileStream(outputFile, FileMode.Create); 
    int data; 
    while ((data = cs.ReadByte()) != -1) fsOut.WriteByte((byte)data); 
    fsOut.Close(); 
    cs.Close(); 
    fsCrypt.Close(); 
}

求助

请问如何借助DirectShow实现从内存直接播放加密视频?

内容的提问来源于stack exchange,提问作者topcool

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:17:16