Xamarin Mac FFmpeg 启动路径不可访问
Xamarin Mac FFmpeg launch path not accessible
我有一个支持 Mac 的 Xamarin Forms 项目,我正在尝试实施 FFmpeg,因此我从其官方页面下载了静态构建并将其添加到 [=26] 的资源文件夹中=] 在 Content 中使用构建操作进行项目,然后我创建了一个服务,该服务基本上会从我在带有 FFmpeg 命令的路径中指示的视频中删除音频,以根据以下答案执行我拥有的服务并且我有将其改编为 C#:
问题是当我尝试执行命令时出现以下错误:
"NSInvalidArgumentException: launch path not accessible"
而我也找不到为什么会这样,我在服务中使用了如下代码(调用NSTask的Launch()方法时出现错误):
public void ExecuteFFmpeg()
{
try
{
var launchPath = NSBundle.MainBundle.PathForResource("ffmpeg", ofType: "");
var compressTask = new NSTask();
compressTask.LaunchPath = launchPath;
compressTask.Arguments = new string[] {
"-i",
"downloads/tyson.mp4",
"-c",
"copy",
"-an",
"nosound.mp4" };
compressTask.StandardInput = NSFileHandle.FromNullDevice();
compressTask.Launch();
compressTask.WaitUntilExit();
}
catch (Exception ex)
{
}
我也已将项目上传到 GitHub,以防有人需要完整查阅存储库:https://github.com/nacompllo/FFmpegSample
如果您未绑定到 NSTask,则可以改用 CliWrapper。
public static async ValueTask FfmpegRemoveAudio(string ffmpegPath, string inputFilePath, string outputFilePath)
{
await Cli.Wrap(ffmpegPath).WithArguments(new[] { "-i", inputFilePath, "-c", "copy", "-an", outputFilePath }).ExecuteAsync();
}
除了 CliWrapper,我还测试了 FfmpegCore and FFmpget.NET that also threw some similar exceptions like you describe. I have no glue, why they behavior different. See the complete working POC 以获取详细信息。
我有一个支持 Mac 的 Xamarin Forms 项目,我正在尝试实施 FFmpeg,因此我从其官方页面下载了静态构建并将其添加到 [=26] 的资源文件夹中=] 在 Content 中使用构建操作进行项目,然后我创建了一个服务,该服务基本上会从我在带有 FFmpeg 命令的路径中指示的视频中删除音频,以根据以下答案执行我拥有的服务并且我有将其改编为 C#:
问题是当我尝试执行命令时出现以下错误:
"NSInvalidArgumentException: launch path not accessible"
而我也找不到为什么会这样,我在服务中使用了如下代码(调用NSTask的Launch()方法时出现错误):
public void ExecuteFFmpeg()
{
try
{
var launchPath = NSBundle.MainBundle.PathForResource("ffmpeg", ofType: "");
var compressTask = new NSTask();
compressTask.LaunchPath = launchPath;
compressTask.Arguments = new string[] {
"-i",
"downloads/tyson.mp4",
"-c",
"copy",
"-an",
"nosound.mp4" };
compressTask.StandardInput = NSFileHandle.FromNullDevice();
compressTask.Launch();
compressTask.WaitUntilExit();
}
catch (Exception ex)
{
}
我也已将项目上传到 GitHub,以防有人需要完整查阅存储库:https://github.com/nacompllo/FFmpegSample
如果您未绑定到 NSTask,则可以改用 CliWrapper。
public static async ValueTask FfmpegRemoveAudio(string ffmpegPath, string inputFilePath, string outputFilePath)
{
await Cli.Wrap(ffmpegPath).WithArguments(new[] { "-i", inputFilePath, "-c", "copy", "-an", outputFilePath }).ExecuteAsync();
}
除了 CliWrapper,我还测试了 FfmpegCore and FFmpget.NET that also threw some similar exceptions like you describe. I have no glue, why they behavior different. See the complete working POC 以获取详细信息。