提问人:J D 提问时间:11/16/2023 最后编辑:J D 更新时间:11/16/2023 访问量:25
AddictedCS SoundFingerprinting FFmpeg.AutoGen System.NullReferenceException
AddictedCS SoundFingerprinting FFmpeg.AutoGen System.NullReferenceException
问:
如何解决以下问题?似乎是 FFmpeg 的类覆盖。
我正在尝试使用 AddictedCS SoundFingerprinting (https://github.com/AddictedCS/soundfingerprinting)。https://github.com/Ruslan-B/FFmpeg.AutoGen
使用 nuget 下载包后,我从源代码下载并编译以调试:
由于某种原因,FFmpeg.AutoGen.Abstractions 不断崩溃。 Visual Studio 2022,项目设置为 X64
例外情况:
FFmpeg.AutoGen.Abstractions 代码行 2906:
公共静态 AVFormatContext avformat_alloc_context() => vectors.avformat_alloc_context();*
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object
Source=FFmpeg.AutoGen.Abstractions
StackTrace:
at FFmpeg.AutoGen.Abstractions.ffmpeg.avformat_alloc_context() in C:\FFmpeg.AutoGen-master\FFmpeg.AutoGen.Abstractions\generated\ffmpeg.functions.facade.g.cs:line 2906
按照建议在正确的位置ffmpeg.exe
C:\fingerPrint\ConsoleApp1\ConsoleApp1\bin\x64\Debug\FFmpeg\bin\x64>ffmpeg.exe ffmpeg version 4.4.1-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 11.2.0 (Rev1, Built by MSYS2 project)
源代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SoundFingerprinting;
using SoundFingerprinting.Builder;
using SoundFingerprinting.Emy;
using FFmpeg.AutoGen.Bindings.DynamicallyLoaded;
using System.IO;
namespace ConsoleApp1
{
internal class Program
{
private readonly IFingerprintCommandBuilder fingerprintCommandBuilder = new FingerprintCommandBuilder();
static async Task Main(string[] args)
{
var current = Environment.CurrentDirectory;
var probe = Path.Combine("FFmpeg", "bin", Environment.Is64BitProcess ? "x64" : "x86");
var ffmpegBinaryPath = Path.Combine(current, probe);
Console.WriteLine(Environment.CurrentDirectory);
Console.WriteLine($"FFmpeg binaries found in: {ffmpegBinaryPath}");
DynamicallyLoadedBindings.LibrariesPath = ffmpegBinaryPath;
var audioService = new FFmpegAudioService();
var hashedFingerprints = await FingerprintCommandBuilder.Instance
.BuildFingerprintCommand()
.From("c:\\temp\\chopin_short2.wav")
.UsingServices(audioService)
.Hash();
}
}
}
接下来我需要看哪里?这不适用于控制台 C# 项目吗?
答:
添加了“DynamicallyLoadedBindings.Initialize();”现在它可以工作了。 要重置并重新启动一切。
> var current = Environment.CurrentDirectory; var probe =
> Path.Combine("FFmpeg", "bin", Environment.Is64BitProcess ? "x64" :
> "x86"); var ffmpegBinaryPath = Path.Combine(current, probe);
> Console.WriteLine(Environment.CurrentDirectory);
> Console.WriteLine($"FFmpeg binaries found in: {ffmpegBinaryPath}");
> DynamicallyLoadedBindings.LibrariesPath = ffmpegBinaryPath;
> DynamicallyLoadedBindings.Initialize();
>
> Console.WriteLine($"FFmpeg version info:
> {ffmpeg.av_version_info()}"); var audioService = new
> FFmpegAudioService(); var hashedFingerprints = await
> FingerprintCommandBuilder.Instance
> .BuildFingerprintCommand()
> .From("c:\\temp\\chopin_short.wav")
> .UsingServices(audioService)
> .Hash(); Console.WriteLine(hashedFingerprints.ToString());
评论