ASP.NET合并图音时Accord.Video.FFMPEG.x64.dll加载失败求助
图片与音频合并生成视频时DLL加载失败问题排查
已尝试的排查操作
- 切换x86、x64程序架构
- 手动将
Accord.Video.FFMPEG.x64.DLL的所有依赖DLL移动到项目bin目录 - 分别使用Accord、Aforge框架测试,复现相同问题
- 安装2013版、2015-2019版VC++可再发行组件
核心实现代码
private const string _basePath = @"D:\R&D Projects\AudioVideoConvertor\VideoAudioMerger\VideoAudioMerger\Images\"; protected void Page_Load(object sender, EventArgs e) { int width = 2500; int height = 2100; int frameRate = 10;// 帧率固定值 using (var videoWriter = new VideoFileWriter()) { videoWriter.Open(_basePath + "test.avi", width, height, frameRate, VideoCodec.WMV1); ResizeNearestNeighbor filter = new ResizeNearestNeighbor(width, height); var images = Directory.GetFiles(_basePath, "*.jpg"); var tfile = TagLib.File.Create(_basePath + "audio.mp3"); TimeSpan duration = tfile.Properties.Duration; decimal timeinSecond = Math.Round((Convert.ToDecimal(duration.TotalSeconds) * frameRate) / images.Length); foreach (string img in images) { using (Bitmap image = Bitmap.FromFile(img) as Bitmap) { // 按音频时长循环写入每帧图片 for (int i = 0; i < timeinSecond; i++) { videoWriter.WriteVideoFrame(filter.Apply(image)); } } } videoWriter.Close(); MergeAudioAndVideo(); } } private static void MergeAudioAndVideo() { File.Delete(_basePath + "mergedvideo.avi"); Process pss = new Process(); ProcessStartInfo si = new ProcessStartInfo(); si.FileName = @"D:\R&D Projects\AudioVideoConvertor\VideoAudioMerger\VideoAudioMerger\ffmpeg-win64-static\bin\ffmpeg.exe"; si.UseShellExecute = false; si.CreateNoWindow = true; si.Arguments = "-i \"" + _basePath + "test.avi\" -i \"" + _basePath + "audio.mp3\" -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 \"" + _basePath + "mergevideo1" + ".avi\""; pss.StartInfo = si; pss.Start(); pss.WaitForExit(); File.Delete(_basePath + "test.avi"); }
运行报错信息
Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found. Stack Trace: [FileNotFoundException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +113 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean forIntrospection) +23 System.Reflection.Assembly.Load(String assemblyString) +35 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49 [ConfigurationErrorsException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +762 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +167 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +238 System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +78 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +334 System.Web.Compilation.BuildManager.ExecutePreAppStart() +178 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +746 [HttpException (0x80004005): Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737
问题根因定位
从堆栈信息能看到,报错是Web应用启动阶段加载bin目录下的Accord.Video.FFMPEG.x64.DLL时触发的,核心触发点包括:
- 架构链路不匹配:虽然项目层面切换了x86/x64,但IIS应用程序池的「启用32位应用」配置、项目目标平台、引用DLL的架构三者没有完全对齐——x64进程无法加载x86原生DLL,x86进程也无法加载x64原生DLL,这个错位会直接触发模块找不到的报错。
- 原生依赖路径不对:Accord.Video.FFMPEG.x64是对FFmpeg原生动态库的封装,Windows加载原生DLL时只会按系统默认搜索顺序查找,不会主动读取子目录下的文件。如果把FFmpeg核心原生依赖(avcodec、avformat、avutil等核心DLL)放在自定义的子文件夹里,就算把托管层的Accord DLL放到bin目录,也会因为找不到原生依赖触发报错。
- 运行库架构不匹配:VC++可再发行组件的x86、x64版本是独立安装的,如果只装了x86版本的运行库,x64版本的原生DLL会因为找不到对应的运行库依赖报模块缺失。
- 权限拦截:IIS应用池的运行身份(默认是ApplicationPoolIdentity)如果没有bin目录的读取执行权限,加载DLL时会被系统拦截,抛出的错误提示和“文件不存在”完全一致,没有明确的权限提示。
落地解决方案
- 统一全链路架构:把对应站点的IIS应用程序池「启用32位应用程序」设置为False,项目目标平台固定为x64,不要使用Any CPU配置,确保应用进程、托管DLL、原生DLL全部是x64架构。
- 修正DLL目录结构:把
Accord.Video.FFMPEG.x64.DLL对应的所有同版本FFmpeg原生依赖文件,全部直接放在站点的bin根目录下,不要放在子文件夹中,避免路径搜索失败。 - 补全运行库:分别安装x64版本的VC++ 2013、2015-2022可再发行组件,安装完成后重启对应IIS应用池。
- 权限校验:给对应应用池的运行身份授予站点bin目录的「读取 & 执行」权限,排除权限拦截问题。
- 优化路径配置:把硬编码的ffmpeg.exe绝对路径改为bin目录下的相对路径,避免部署时路径找不到的问题,同时减少临时文件的读写逻辑。
内容的提问来源于stack exchange,提问作者Sandeep Kumar
相关产品推荐
相关产品推荐

