FFMPEG 在部署后的应用服务中不起作用

问题描述 投票:0回答:1

我使用 Xabe.FFmpeg 包从视频生成剪辑。该代码基本上是将视频转换为多个剪辑,它在我的本地工作正常,但每当我将代码上传到应用程序服务时,代码就无法工作。

堆栈:.net 应用服务操作系统:Windows

错误:

2024-02-13 08:57:34.092 +00:00 [错误] Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer:连接ID“16573246629528734243”,请求ID“40000a24-0000-e600-b63f-84710c7967bb”: application.System.ComponentModel.Win32Exception (193) 引发了未处理的异常:尝试使用工作目录“C:\”启动进程“C:\home\site\wwwroot\Controllers fmpeg in fmpeg.exe”时发生错误主页\站点\wwwroot'。指定的可执行文件不是此操作系统平台的有效应用程序。at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)at System.Diagnostics.Process.Start()at Xabe.FFmpeg.FFmpeg.RunProcess(String args, String processPath, Nullable

1 priority, Boolean standardInput, Boolean standardOutput, Boolean standardError)at Xabe.FFmpeg.FFmpegWrapper.<>c__DisplayClass14_0.<RunProcess>b__0()at System.Threading.Tasks.Task
1.InnerInvoke()at System.Threading.Tasks.Task.<>c.<.cctor>b__281_0(Object obj)at System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate)---结束来自先前位置的堆栈跟踪 ---at System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext, ContextCallbackcallback, Object state)at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)--- 堆栈结束从先前位置跟踪 ---位于 C:\Users ushar.h.gupta 中的 ExtractResponseAPI.Controllers.HomeController.PrepareVideoClips(CloudBlockBlob sourceVideoBlob, TimeSpan startTime, TimeSpan endTime) 处的 Xabe.FFmpeg.Conversion.Start(String参量, CancellationToken CancellationToken) \来源 epos\ExtractResponseAPI\Controllers\HomeController.cs:第 164 行位于 C:\Users ushar.h.gupta\source 中的 ExtractResponseAPI.Controllers.HomeController.GetIntervalsAsync(String query) epos\ExtractResponseAPI\Controllers\HomeController.cs:第 60 行位于 C:\Users ushar.h.gupta\source 中的 ExtractResponseAPI.Controllers.HomeController.Get(字符串查询) epos\ExtractResponseAPI\Controllers\HomeController.cs:line 24at lambda_method4(Closure, Object)at Microsoft.AspNetCore.Mvc.Infrastruct.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext、IActionResultTypeMapper 映射器、ObjectMethodExecutor 执行器、对象控制器、Object[] 参数)在 Microsoft.AspNetCore.Mvc.Infrastruct.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker 调用程序,ValueTask
1 actionResultValueTask)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT
1.ProcessRequestAsync()

代码:

private async Task<List<string>> PrepareVideoClips(CloudBlockBlob sourceVideoBlob, TimeSpan startTime, TimeSpan endTime)
{
    string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

    // Create a temporary directory to store clips locally
    Directory.CreateDirectory(tempDirectory);

    // Download the source video
    string sourceVideoPath = Path.Combine(tempDirectory, "sourceVideo.mp4");
    await sourceVideoBlob.DownloadToFileAsync(sourceVideoPath, FileMode.Create);
    FFmpeg.SetExecutablesPath("Controllers\\ffmpeg\\bin\\");
    // Use FFmpegCore to trim the video
    string outputVideoPath = Path.Combine(tempDirectory, "output.mp4");

    await FFmpeg.Conversions.New()
        .AddParameter($"-ss {startTime.TotalSeconds}") // Start time
        .AddParameter($"-i {sourceVideoPath}")
        .AddParameter($"-to {(endTime - startTime).TotalSeconds}") // Duration
        .SetOutput(outputVideoPath)
        .Start();

    // Return a list of file paths for the clips
    return new List<string> { outputVideoPath };
}

我尝试使用不同的操作系统部署应用程序服务,但仍然面临同样的问题,我也尝试使用不同的包,但结果是相同的。

.net ffmpeg azure-web-app-service
1个回答
0
投票

System.ComponentModel.Win32Exception (193):尝试使用工作目录“C:\home\site\wwwroot”启动进程“C:\home\site\wwwroot\fmpeg.exe 中的控制器 fmpeg”时发生错误。指定的可执行文件不是此操作系统平台的有效应用程序。

问题在于 Azure 应用服务上的 FFmpeg 可执行文件的路径。该错误消息表明应用程序无法在指定路径中找到 FFmpeg 可执行文件

/app/wwwroot/ffmpeg

在上面问题给出的代码中:

string sourceVideoPath = Path.Combine(tempDirectory, "sourceVideo.mp4");
await sourceVideoBlob.DownloadToFileAsync(sourceVideoPath, FileMode.Create);
FFmpeg.SetExecutablesPath("Controllers\\ffmpeg\\bin\\");

似乎将

SetExecutablesPath
与相对路径一起使用可能不是最可靠的方法,尤其是在可以以不同方式管理路径的 Azure 应用服务环境中。

  • 相反,您可以将 FFmpeg 可执行文件与应用程序一起上传,并使用相对路径或通过在应用程序中指定绝对路径来引用它们。

使用以下路径:

// Assuming the ffmpeg directory is located in the root directory of your application
string ffmpegDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg", "bin");

// Specify the path to the FFmpeg executables
FFmpeg.SetExecutablesPath(ffmpegDirectory);
  • AppDomain.CurrentDomain.BaseDirectory
    为您提供应用程序的基目录,您可以将路径连接到
    ffmpeg
    目录中的 FFmpeg 可执行文件。

.csproj 文件:

<Project Sck="Microsoft .NET.Sdk.WebjMicrosoft .NET.Sdk .Publish">
<PropertyGroup>
<Output Type>Exe</OutputType>
<TargetFrameorkonetcoreapp2.@</TargetFramework>
<RuntimeIdentifiers>winl@-x64</RuntimeTdentifiers>

</PropertyGroup>
<ItenGroup>
<PackageReference
<PackageReference 1.6.19" />
<PackageReference fangFire.SqlServer" Version="1.6.19" />
<PackageReference \icrosoft AsplletCore.All” Version="2.0.7" />
<PackageReference Microsoft ApplicationInsights.AsplietCore" Versions"
<PackageReference \icrosoft. EntityFrameworkCore.Sqlserver” Version

insole” Version:

“<Packagenererence
<7TEemGroup>
‘itenGroup>

<ProjectReference
TEEROTOOD
TeenGroup>
<llone Updates"Assets\-Fnpeg.exe">
<CopyToOutputDirectory Alway3</ Copy TeOutputDirectory>
<itione>
‘lone Updeten"Assets\$fprobe.exe">
<CopyToOutputDirectory »Always</CopyTeOutputDirectory>
<itione>
<llone Updeten"Assets unknown png">
<CopyToOutputDirectory >AlNay'3</CopyTeOutputDirectory>
<itione>
‘lone Updete="Fémpeg.exe">
<CopyToOutputDirectory »Always</CopyTeOutputDirectory>
<itione>
‘lone Usdate="F¥probe.exe">
<CopyToOutputDirectory »Always</CopyTeOutputDirectory>
Briones]
/ TtenGroup>
</POTECE

执行: enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.