将视频转换为字节数组
问题描述:
亲爱的所有
请将视频文件(AVI-MP4)转换为字节数组,我有路径
什么是最好的方式
这是我使用但是当文件大的时候给我内存错误
请如何转换它
Dear all
Please i want to convert video file (AVI - MP4) to byte array and i have the path
what is the best way
this is i used but when file large give me memory error
please how to convert it
videobytes= File.ReadAllBytes(filepath);
答
文件大并没有告诉我们多少:我看过几个视频文件巨型到接近一个太字节!
但是......问题几乎肯定无法解决。如果您的视频文件超过2GB,那么您无法在.NET中将其作为单个数组加载 - 没有单个对象(并且字节数组是单个对象,因为字节是值类型,而不是引用)可能超过在任何情况下都是2GB。
因此你必须使用流加载它:你无法将整个文件读入内存。
"File large" doesn't tell us much: I've seen video files ranging from a couple of mega to nearly a terrabyte!
But...the problem is almost certainly unsolvable. If your video file exceeds 2GB, then there is nothing you can do in .NET to load it as a single array - no single object (and an array of bytes is a single object because byte is a value type, not reference) can exceed 2GB under any circumstances.
So you will have to load it in chunks using a stream: you can't read the whole file into memory.