视频播放内存流

时间:2014-01-23 06:17:56

标签: asp.net video

我在asp.net c#中工作。我想从内存流播放视频。我正在加密和解密视频。我将解密的视频存储在内存流中,并且想要播放它而不保存。我用Google搜索并找到帖子的数量,但主要是帖子未完成或提供了与directshow的链接。我也尝试过directshow,但它对我来说是全新的并包含一些演示,这使得混淆哪一个用于内存流。

我只想从内存流中播放解密的视频数据。请让我知道我能做些什么,如果有任何论坛提供样本会更好。

我的解密代码

public bool DecryptData(String inName, String outName, byte[] rijnKey, byte[] rijnIV)
{
   FileStream fin = null;
    FileStream fout = null;
    CryptoStream decStream = null;

    try
    {
            fin = new FileStream(inName, FileMode.Open, FileAccess.Read);

            //Create variables to help with read and write.

            byte[] bin = new byte[bufLen]; //This is intermediate storage for the encryption.
            long rdlen = 0; //This is the total number of bytes written.
            long totlen = fin.Length; //This is the total length of the input file.
            int len; //This is the number of bytes to be written at a time.
            RijndaelManaged rijn = new RijndaelManaged();

            //DES ds = new DESCryptoServiceProvider();

            decStream = new CryptoStream(fin, rijn.CreateDecryptor(rijnKey, rijnIV), CryptoStreamMode.Read);


            //odkoduj testowy fragment

            byte[] test = new byte[testHeader.Length];
            decStream.Read(test, 0, testHeader.Length);
            string contents = new StreamReader(decStream).ReadToEnd();
            byte[] unicodes = Encoding.Unicode.GetBytes(contents);
            MemoryStream msOutput = new MemoryStream(unicodes);
//here I have to implement player that plays from memory stream.
}
catch
{}
}

2 个答案:

答案 0 :(得分:0)

我已经回答了有关视频文件加密和解密的一个问题,但是我可以理解,您不想在客户端计算机上保存该文件的物理副本。

https://stackoverflow.com/a/58129727/9869635

但是无法从memorystream播放视频文件(不确定某些付费的第三方工具)

因此,您可以按照以下方法之一进行操作:

1:将该文件保存在客户端的“ temp”文件夹中,例如“ temp / myvideos / sample.mkv”

2:将其从属性(How to hide file in C#?)中隐藏起来

3:从那里播放视频

4:播放后,从“ temp”文件夹(myvideos)中删除该自定义文件夹中的所有文件。

答案 1 :(得分:-1)

今天最好的方法,适用于任何平台...是使用Http Live Streaming然后你可以使用支持HLS的播放器,或者你可以简单地使用HTML5视频标签。请参阅下面的更新答案...

Play a video without a file on disk [Java]

相关问题