Click here to Skip to main content
15,894,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
videobytes=   File.ReadAllBytes(filepath);
Posted
Comments
DamithSL 1-Nov-14 9:40am    
what is the error?
beljk 1-Nov-14 9:46am    
First,, is this the best way or what ???
beljk 1-Nov-14 9:46am    
System.OutOfMemoryException
DamithSL 1-Nov-14 9:50am    
:) it is good option for small files, this will load entire file to memory, if you have enough memory to hold entire file, then no issues.
Tomas Takac 1-Nov-14 9:53am    
Well, you are loading the entire file into memory. For that you better have that memory available. What do you plan to do with the byte array?

1 solution

"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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900