Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear all,

 

Let's say I am streaming a video file on a local http port. I would like to split the file when it reaches say 2Gb in length. I've managed to start saving the file but for the life of me I cannot find anything regarding creating a new file when the original one reaches a certain size.

 

I've taken this code from an example I've found on this forums:

 

Dim FileStreamer As New FileStream(Application.StartupPath & "\" & Filename & "(" & fileSplitNumber.ToString & ").mpg", FileMode.Create)

 

 

fileSplitNumber is an integer that would increment with every split. What I don't understand is how to "ReDim" the FileStreamer object to create a new file and continue streaming to it where it left off from the old one. I use FileStreamer.Length to check how much has been streamed.

 

Any help (code!) would be greatly appreciated :D

 

Thanks

 

CJ

Posted

i think this pseudo code is an effective procedure:

 

 

fileSize = z 
readSize = x
BytesRead = 0
TotalBytes = 0
Create array[x]
i = 0

while Socket.Available <> 0 
begin
if (TotalBytes=0) then 
begin
	create filestream(filename_i)
	create binaryWriter(filestream)
end 
TotalBytes += BytesRead = Socket.Receive(array)
binarywriter.write(array,0, BytesRead)
if (Socket.Available = 0) or (TotalBytes>=filesize) then 
begin
	binarywriter.close
	filestream.close
	TotalBytes = 0
	i++
end 
end

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted (edited)

Thanks for the reply. The pseudo code I understand perfectly, but I don't understand how to create a new file after closing the file streamer.

 

Dim FileStreamer As New FileStream(Filename & i, FileMode.Create)

 

This is what I do at the start of the function. But once I reach the max file size, how do I create a new file and continue writing to it? ReDim statement doesn't seem to work. And it doesn't let me do FileStreamer = FileStream(...) either as types cannot be used in expressions. And if at all possible without losing any data in the process so I can join them later?

 

Thanks

Edited by Captain Jack
Posted
FileStreamer = New FileStream(Application.StartupPath & "\" & Filename & "(" & fileSplitNumber.ToString & ").mpg", FileMode.Create)

just make sure you've closed the previous file before executing the above line of code.

 

Yay! Thanks for that.. Seems to work OK, although still not completely seemless. Some bytes get lost in the process.

 

OK another question, when it's writing to the disk, the program seems to freeze. I have Application.DoEvents within the loop and this does seem to help although, still not perfect. Could it be it's waiting for more data when it freezes?

Posted
It could be listening for more data...I would say that it is also possible that it is freezing because of the writing to disk. Defrag and see if the freezing time reduces.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted
Yes' date=' looks like it's waiting for data while "frozen" as the byte counter goes up when it's receiving data. I assume there's no way of making it more "fluent"?[/quote']

yes. . . Do some research on blocking/non-blocking and asynchronisity with regards to sockets.

 

someone probably has a link at the ready.

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...