[英]how to split a wmv file
im doing a application in which i split a wmv file and transfer it to otherlocation(in 'x' kbs) .after the transfer gets completed the file doesnt play,it gives a message as the format is not supported.is there anyother way to do it. 我正在做一个应用程序,其中我拆分了一个wmv文件并将其传输到otherlocation(以'x'kbs)。传输完成后,该文件无法播放,由于不支持该格式,它会发出一条消息。是否还有其他方法可以做吧。
sory i will explain what im doing now 对不起,我将解释我现在在做什么
i wrote an remote application,i want to transfer a .wmv file from one machine to other,i want to split the .wmv and send it to the remote machine and use it there.if i try to send the complete file means it will take lot of memory that seems very bad.so i want to split it and send it.but the file doesnt gets played it raises an exception the format is not supported. 我编写了一个远程应用程序,我想将.wmv文件从一台计算机传输到另一台计算机,我想将.wmv文件拆分并发送到远程计算机并在其中使用。如果我尝试发送完整文件,则它将占用大量内存,这似乎非常糟糕。所以我想将其拆分并发送。但是文件没有播放,它引发了一个不支持格式的异常。
the following is the code im doing i just done it in the local machine itself(not remoting): 以下是我正在本地计算机本身中完成的代码(不远程处理):
try
{
FileStream fswrite = new FileStream("D:\\Movie.wmv", FileMode.Create);
int pointer = 1;
int bufferlength = 12488;
int RemainingLen = 0;
int AppLen = 0;
FileStream fst = new FileStream("E:\\Movie.wmv", FileMode.Open);
int TotalLen = (int)fst.Length;
fst.Close();
while (pointer != 0)
{
byte[] svid = new byte[bufferlength];
using (FileStream fst1 = new FileStream("E:\\Movie.wmv", FileMode.Open))
{
pointer = fst1.Read(svid, AppLen, bufferlength);
fst1.Close();
}
fswrite.Write(svid, 0, pointer);
AppLen += bufferlength;
RemainingLen = TotalLen-AppLen;
if(RemainingLen < bufferlength)
{
byte[] svid1 = new byte[RemainingLen];
using (FileStream fst2 = new FileStream("E:\\Movie.wmv", FileMode.Open))
{
pointer = fst2.Read(svid1, 0, RemainingLen);
fst2.Close();
}
fswrite.Write(svid, 0, pointer);
break;
}
}
fswrite.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
您可能会发现在C#中通过网络发送大文件的好方法很有帮助。
Im going to make the assumtion your spliting the file when your sending it, and not trying to have the wmv in 3 different files on the remote machine. 我将假设您在发送文件时将文件拆分,而不是尝试在远程计算机上的3个不同文件中包含wmv。
When your sending the file what you basicly do is this: 发送文件时,基本上要做的是:
Local machine 本地机器
1) Read 16k bytes ( Or whatever number you prefere ) 1)读取16k字节(或您喜欢的任何数字)
2) Send those 16k bytes over the network 2)通过网络发送那些16k字节
3) Repeat above steps untill done 3)重复上述步骤,直到完成
Remote machine 遥控机器
1) Listen for a connection 1)听连接
2) Get 16k bytes 2)获得16k字节
3) Write 16k bytes 3)写入16k字节
4) Repeat untill done. 4)重复直到完成。
This method will work, but your kind of inventing the wheel again, i would recommend using either something as simple as File.Copy ( Works fine over the network ) or if that does not meet your needs perhaps using a FTP client / server solution ( Plenty of C# examples on the net that can be hosted inside your application ). 这种方法可以用,但是您还是想重新发明轮子,我建议您使用File.Copy之类的简单方法(可以在网络上正常工作),或者如果它不能满足您的需求,则可以使用FTP客户端/服务器解决方案(可以在您的应用程序内部托管的网上很多C#示例。
i tried this 我尝试了这个
private void Splitinthread()
{
int bufferlength = 2048;
int pointer = 1;
int offset = 0;
int length = 0;
byte[] buff = new byte[2048];
FileStream fstwrite = new FileStream("D:\\TEST.wmv", FileMode.Create);
FileStream fst2 = new FileStream("E:\\karthi.wmv", FileMode.Open);
int Tot_Len = (int)fst2.Length;
int Remain_Buff = 0;
//Stream fst = File.OpenRead("E:\\karth.wmv");
while (pointer != 0)
{
try
{
fst2.Read(buff, 0, bufferlength);
fstwrite.Write(buff, 0, bufferlength);
offset += bufferlength;
Remain_Buff = Tot_Len - offset;
Fileprogress.Value = CalculateProgress(offset, Tot_Len);
if (Remain_Buff < bufferlength)
{
byte[] buff1 = new byte[Remain_Buff];
pointer = fst2.Read(buff1, 0, Remain_Buff);
fstwrite.Write(buff1, 0, pointer);
Fileprogress.Value = CalculateProgress(offset, Tot_Len);
fstwrite.Close();
fst2.Close();
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
MessageBox.Show("Completed");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.