How to crop a mp3 in ASP.NET + C#?

半腔热情 提交于 2019-12-22 12:34:12

问题


I am in an ASP.NET project using C#. The users can upload their MP3 (I have no control over the encoding) and specify a sample size and a sample starting point. On save, the system needs to create a sample of this MP3 based on the information provided.

So the question is: How can Icrop a mp3 in ASP.NET + C#??


回答1:


While you could possibly use a .NET audio library to do this, I think the easiest way to do this would be to run a command like FFMpeg or MPlayer to do the cropping for you, then send the file back down the line.

For example, with FFMpeg, you can do something like this (from here crops up to the 90th second):

ffmpeg -ss 90 -i input.mp3 output.mp3

To start FFMpeg, use something like this:

System.Diagnostics.Process p = new System.Diagnostics.Process();
Response.Write("Cutting MP3...");
Response.Flush();
p.StartInfo = new System.Diagnostics.ProcessStartInfo("ffmpeg.exe", "-s 90 -i " + inputFile + " " + outputFile);
p.Start();
p.WaitForExit();
Response.Write("Done");

The only problem is that it takes quite a while and it's hard to report progress back to the user.




回答2:


You can split the file using the MP3 frame headers. Using a simple brute force search you can split the file into separate frames and create a new MP3 that is as long as you wish.

MP3 Format



来源:https://stackoverflow.com/questions/1386818/how-to-crop-a-mp3-in-asp-net-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!