如何在MVC中使用gzip压缩视频文件?

时间:2016-05-21 06:39:24

标签: c# video model-view-controller compression gzip

尝试使用gzip压缩视频,视频被压缩并保存在数据库中,但是当我尝试使用视频标签播放时,它就无法工作。

当我尝试手动播放视频时,它也无法在VLC或任何媒体播放器中播放。

我的目标是上传视频并在保存到数据库之前对其进行压缩。视频可以是视频标记支持的任何格式。

FileStream compressedFileStream;
compressedFileStream = new FileStream(fullPath1, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[compressedFileStream.Length];
int count = compressedFileStream.Read(buffer, 0, buffer.Length);
if (count != buffer.Length)
{
    compressedFileStream.Close();
    Console.WriteLine("Test Failed: Unable to read data from file");
    //return;
}
compressedFileStream.Close();
MemoryStream ms = new MemoryStream();
GZipStream compressedzipStream = new GZipStream(ms, CompressionLevel.Optimal, true);
compressedzipStream.Write(buffer, 0, buffer.Length);
// Close the stream.
compressedzipStream.Close();
Console.WriteLine("Original size: {0}, Compressed size: {1}", buffer.Length, ms.Length);
Array.ForEach(Directory.GetFiles(fileDirectory1), System.IO.File.Delete);
FileStream fileaftrcmprsn = new FileStream(fullPath1, FileMode.Create, FileAccess.Write);
ms.WriteTo(fileaftrcmprsn);                         
fileaftrcmprsn.Close();

0 个答案:

没有答案