gpt4 book ai didi

c# - 使用 C# 将视频 MP4 音频转换为 MP3

转载 作者:行者123 更新时间:2023-12-04 22:55:33 28 4
gpt4 key购买 nike

我有一些 MP4 格式的视频,我正在尝试从中提取音频。

我的代码是:

public static void Converter(string toConvert)
{
toConvert = VideoFile + ".mp4";

var join = VideoFile.Split("-").ToList();

VideoFile = string.Format("{0} - {1}", join[0], join[1]);

var outputFile = VideoFile + ".mp3";
var mp3Out = "";

var ffmpegProcess = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = Directory,
Arguments = " -i " + toConvert + " -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);
}

但是,我收到此错误消息:

System.ComponentModel.Win32Exception: 'Access is denied'



有任何想法吗?

最佳答案

从评论中我了解到 Directory变量包含视频的路径,您可以在 FileName 上设置它用于流程启动信息。 FielNameStartInfo应该包含 ffmpeg 可执行文件的路径。前任:

public static string FFMpegPath { get; private set; } = @"d:\tmp\ffmpeg\ffmpeg-20180119-07a96b6-win64-static\bin\ffmpeg.exe";

var ffmpegProcess = new Process
{
StartInfo =
{
....
FileName = FFMpegPath
}
};

如果我设置 FileName到一个目录(例如: d:\Videos\)我得到和你一样的错误

关于c# - 使用 C# 将视频 MP4 音频转换为 MP3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48354603/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com