C# 使用FileStream将mp3文件合并为一个文件
我使用下面非常简单的代码,使用C# 使用FileStream将mp3文件合并为一个文件,c#,winforms,C#,Winforms,我使用下面非常简单的代码,使用FileStream合并6个mp3文件,看起来非常简单。虽然合并是可以的,但是当我检查新生成的文件时,它比原始的6个mp3文件短6秒。下面,我还粘贴了带有单个文件持续时间的代码 string dirPath = @"C:\downloads\114\"; FileInfo[] files = new DirectoryInfo(dirPath).GetFiles(); // 6 audio files to merge foreach (var file in fi
FileStream
合并6个mp3文件,看起来非常简单。虽然合并是可以的,但是当我检查新生成的文件时,它比原始的6个mp3文件短6秒。下面,我还粘贴了带有单个文件持续时间的代码
string dirPath = @"C:\downloads\114\";
FileInfo[] files = new DirectoryInfo(dirPath).GetFiles(); // 6 audio files to merge
foreach (var file in files)
{
using (var f = file.Open(FileMode.Open))
{
byte[] bytes = new byte[f.Length];
using (FileStream isfs = new FileStream(dirPath + "114.mp3", FileMode.OpenOrCreate))
{
isfs.Seek(0, SeekOrigin.End); //go to the last byte
while (f.Read(bytes, 0, bytes.Length) > 0)
{
isfs.Write(bytes, 0, bytes.Length);
isfs.Flush();
}
}
}
}
文件持续时间(秒):
#File #Duration in Seconds
114000.mp3 6.64 sec
114001.mp3 5.935 sec
114002.mp3 4.864 sec
114003.mp3 4.838 sec
114004.mp3 7.58 sec
114005.mp3 7.554 sec
114006.mp3 6.431 sec
总持续时间为:43.842秒
#The new Generated File
114.mp3 37.198 seconds
问题是:
长度
是相同的!
谢谢 1)您不是在合并mp3文件,而是在合并二进制文件。你必须考虑到标题等,否则合并将不起作用。。。(在您的情况下,在文件的中间有更多的页眉,并且不能保证文件之间的比特率相同)
2) 看看,也许对你也有帮助 谢谢,我觉得这里有些有趣的东西。使用
Microsoft.WindowsAPICodePack.Shell
和WMPLib
,合并文件或合并二进制文件的持续时间分别为43秒和37秒。我不知道哪一个是正确的?是不是相反,用二进制合并37秒?给你43秒的应该是正确的:)嗯,我用两种不同的方法检查了两个文件(Windows Media PlayerWMPLib
和Microsoft.WindowsAPICodePack.Shell
我确信它在Media Player中显示37秒,在其他API中显示43秒。mp3wrap不能合并超过255个文件!@ARH一次合并255个文件,那么?