AddictedCS / soundfingerprinting

Open source audio fingerprinting in .NET. An efficient algorithm for acoustic fingerprinting written purely in C#.
https://emysound.com
MIT License
945 stars 188 forks source link

Unable to build fingerprints with ffmpeg on Windows 10 - System.ApplicationException : Invalid argument #182

Closed Bryan-Rose closed 2 years ago

Bryan-Rose commented 2 years ago

Describe the bug Running the sample code with the ffmpeg audio service, I am unable to create fingerprints from mp3 or wav files. The wav file worked with the default SoundFingerprintingAudioService

To Reproduce Use the following code and the attached file GHIssue_Sample.zip

I also downloaded the tools from ffmpeg v4.3.2 and have them in the correct location. (Files are copied to the correct output folder on build)

image

Nuget packages

<PackageReference Include="SoundFingerprinting" Version="8.5.1" />
<PackageReference Include="SoundFingerprinting.Emy" Version="8.5.1" />
public class GHIssue
    {
        public string sampleFile = @"path\to\file\GHIssue_Sample.mp3";

        private readonly IModelService modelService = new InMemoryModelService(); // store fingerprints in RAM
        private readonly FFmpegAudioService ffmpegService = new FFmpegAudioService(); // default audio library

        public async Task StoreForLaterRetrieval()
        {
            var track = new TrackInfo("Sample1", "Title1", "Artist1");

            // create fingerprints
            var avHashes = await FingerprintCommandBuilder.Instance
                                        .BuildFingerprintCommand()
                                        .From(sampleFile, MediaType.Audio)
                                        .UsingServices(ffmpegService)
                                        .Hash();

            // store hashes in the database for later retrieval
            modelService.Insert(track, avHashes);
        }
    }

Screenshots image


  Message: 
System.ApplicationException : Invalid argument

  Stack Trace: 
ErrorExtensions.ThrowExceptionIfError(Int32 error)
AudioConverter.InitResampler()
AudioConverter.ctor(AudioFormat input, AudioFormat output, SwrEngine engine)
<>c__DisplayClass7_0.<CreateAudioConverters>b__0(AudioDecoder decoder)
SelectEnumerableIterator`2.ToList()
Enumerable.ToList[TSource](IEnumerable`1 source)
FFmpegDataService.CreateAudioConverters(IEnumerable`1 decoders, AudioFormat outputAudioFormat)
FFmpegDataService.ReadAVTrack(String source, MediaType mediaType, Double seconds, Int32 count, AVTrackReadConfiguration avTrackReadConfiguration, CancellationToken cancellationToken)+MoveNext()
List`1.ctor(IEnumerable`1 collection)
Enumerable.ToList[TSource](IEnumerable`1 source)
<11 more frames...>
--- End of stack trace from previous location ---
GHIssue.StoreForLaterRetrieval() line 28
Tests.sample() line 34
GenericAdapter`1.BlockUntilCompleted()
NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.<Execute>b__0()
BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Desktop (please complete the following information):

AddictedCS commented 2 years ago

It seems the version that you have was built without --enable-libsoxr flag. Try the following build v4.4.1 which has the flag enabled: https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4.1-full_build-shared.7z

Bryan-Rose commented 2 years ago

Awesome, that fixed it. Thank you!