2017-07-08 262 views
-1

是否有任何简单的方法从mp4文件中提取mp3文件?c#从mp4文件中提取mp3文件

我已经尝试更改文件扩展名,但这不会让我编辑mp3说明。

谢谢!使用FFMPEG

+1

可能重复的[从视频文件提取wav文件](https://stackoverflow.com/questions/1010937/extract-wav-file-from-video-file) –

+0

我认为你的问题应该是“我怎么能以编程方式在c#中设置'mp3'的描述。这听起来像你完全有能力'mp4' - >'mp3',你只需要帮助设置描述。 –

回答

1

你可以做这样的事情:

using System; 
using System.Diagnostics; 

namespace ConvertMP4ToMP3 
{ 
    internal class Program 
    { 
     static void Main(string[] args) 
     { 
      var inputFile = args[0] + ".mp4"; 
      var outputFile = args[1] + ".mp3"; 
      var mp3out = ""; 
      var ffmpegProcess = new Process(); 
      ffmpegProcess.StartInfo.UseShellExecute = false; 
      ffmpegProcess.StartInfo.RedirectStandardInput = true; 
      ffmpegProcess.StartInfo.RedirectStandardOutput = true; 
      ffmpegProcess.StartInfo.RedirectStandardError = true; 
      ffmpegProcess.StartInfo.CreateNoWindow = true; 
      ffmpegProcess.StartInfo.FileName = "//path/to/ffmpeg"; 
      ffmpegProcess.StartInfo.Arguments = " -i " + inputFile + " -vn -f mp3 -ab 320k output " + outputFile; 
      ffmpegProcess.Start(); 
      ffmpegProcess.StandardOutput.ReadToEnd(); 
      mp3out = ffmpegProcess.StandardError.ReadToEnd(); 
      ffmpegProcess.WaitForExit(); 
      if (!ffmpegProcess.HasExited) 
      { 
       ffmpegProcess.Kill(); 
      } 
      Console.WriteLine(mp3out); 
     } 
    } 
} 

也许?在这里您可以通过命令行调用.exe文件的输入和输出文件路径减去扩展名:a:

C:\> ConvertMP3ToMP4.exe C:\ Videos \ Aqua \ BarbieGirl C:\ Music \ Aqua \ BarbiGirl

您当然需要在第19行提供FFMPEG可执行文件的完整路径。这里有个小警告,我只是回过头来说明代码可能有问题,我没有编译或测试它,这只是一个起点。祝你好运。