简体   繁体   English

如何以 C# 语言实现的字节拆分 wmv 文件?

[英]How to split a wmv file in bytes implemented in C# language?

I have a wmv file whose size is 300 bytes.我有一个大小为 300 字节的 wmv 文件。 I want to split it into several bytes (example: (150 bytes each) or (3 100 bytes)).我想将它分成几个字节(例如:(每个 150 字节)或(3 100 字节))。 How do I implement this in C# Language?如何在 C# 语言中实现这一点?

It really depends on whether you want the files to work or not.这实际上取决于您是否希望文件正常工作。 Splitting them in chunks is easy: Read them into a byte array, have a for loop that copies part of the array to a file of size CHUNK, without forgetting to copy the final bytes of the file.将它们分成块很容易:将它们读入一个字节数组,有一个 for 循环将数组的一部分复制到一个大小为 CHUNK 的文件中,而不会忘记复制文件的最终字节。 Splitting them in working files is different.将它们拆分为工作文件是不同的。

I would try to just stream it without explicit splitting (the tcp stack will split it as it likes^^).我会尝试只使用 stream 而不进行显式拆分(tcp 堆栈会根据需要拆分它^^)。 If you have a good codec it will play it anyway.如果你有一个好的编解码器,它无论如何都会播放它。 (Vlc can always plays the videos while downloading) (Vlc 可以在下载时始终播放视频)

The real answer is, just use a streaming server and forget about writing a streaming protocol.真正的答案是,只需使用流式服务器,而无需编写流式协议。 Thats crazy.太疯狂了。 To split a file into byte segments you could use something like the code below.要将文件拆分为字节段,您可以使用类似下面的代码。 Not thats untested, but it should be about 95% complete.这不是未经测试的,但它应该完成了大约 95%。

You should take a look at the proto spec if you havent already.如果你还没有,你应该看看 proto 规范。 http://msdn.microsoft.com/en-us/library/cc251059(v=PROT.10).aspx And if you have, and you asked this question, you dont stand an ice cubes chance in hell at making it work, http://msdn.microsoft.com/en-us/library/cc251059(v=PROT.10).aspx如果你有,并且你问了这个问题,那么你就没有机会让它发挥作用,

        int chunkSize = 300;
        var file = File.Open("c:\file.wmv", FileMode.Open);
        var numberOfChunks = (file.Length/chunkSize)+1;
        byte[][] fileBytes = new byte[numberOfChunks][];
        for (int i = 0; i < numberOfChunks; i++)
        {
            int bytesToRead = chunkSize;
            if (i == numberOfChunks + 1)
            {
                bytesToRead = (int)(file.Length - (i * chunkSize));
            }
            fileBytes[i] = new byte[bytesToRead];
            file.Read(fileBytes[i], i * chunkSize, bytesToRead);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM