以下代码将大型600mb音频wav文件拆分为按钮点击事件中的两个部分..
protected void Button1_Click(object sender, EventArgs e)
{
string inputFile = Server.MapPath("~/inputPath/BetterFasterCheaperGovt-HD+720p.wav"); // Substitute this with your Input File
FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
int numberOfFiles = 2;
int sizeOfEachFile = (int)Math.Ceiling((double)fs.Length / numberOfFiles);
for (int i = 1; i <= numberOfFiles; i++)
{
string baseFileName = Path.GetFileNameWithoutExtension(inputFile);
string extension = Path.GetExtension(inputFile);
FileStream outputFile = new FileStream(Path.GetDirectoryName(inputFile) + "\\" + baseFileName + "_" + i.ToString().PadLeft(3, Convert.ToChar("0")) + extension, FileMode.Create, FileAccess.Write);
int bytesRead = 0;
byte[] buffer = new byte[sizeOfEachFile];
if ((bytesRead = fs.Read(buffer, 0, sizeOfEachFile)) > 0)
{
outputFile.Write(buffer, 0, bytesRead);
}
outputFile.Close();
}
fs.Close();
ClientScript.RegisterStartupScript(this.GetType(), "popup", "alert('success');", true);
}
它成功地分成两个相同大小的文件,即300mb但是 part1.wmv是300mb,显示长度为1小时16分钟 part2.wmv是300mb长度是0。
表示part2.wav中没有音频,只创建了空白损坏的文件。
请帮我解决问题。 谢谢!
答案 0 :(得分:1)
查看Windows Media Encoder SDK。像这样:
Int32 StartTime = 0;
Int32 EndTime = 76 * 1000; //1hr 16min
String SourceName = "original.mp3";
String DestinationName = "newsplit.mp3";
WMEncBasicEdit SplitFile = new WMEncBasicEdit();
SplitFile.MediaFile = SourceName;
SplitFile.OutputFile = DestinationName;
SplitFile.MarkIn = StartTime;
SplitFile.MarkOut = EndTime;
SplitFile.Start();