rosenbjerg/FFMpegCore

The type initializer for 'FFMpegCore.Enums.FileExtension' threw an exception

yangbocheng opened this issue · 4 comments

i got this exception when testing var z = FileExtension.Png

while i have set the ffmpeg bin path then FFProbe.Analyse(mp4) work well.

please give some sugguestions about solving this exception!

here is my console-test setting

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FFMpegCore" Version="5.1.0" />
    <PackageReference Include="FFMpegCore.Extensions.SkiaSharp" Version="5.0.0" />
  </ItemGroup>

</Project>

ffmepg is from https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n6.1-latest-win64-gpl-6.1.zip

Would probably be helpful to have an example of your unit test - FFMpegCore.Enums.FileExtension.Png is just a static pseudo-constant, so that's not going to throw an exception.

The Extension() method will throw an exception if you pass it a Codec which this library doesn't recognize. That could be the case if the MP4 you're analyzing was encoded using H.265 rather than H.264, for instance.

thanks .
with sourcecode debug, i found that it's my fault: i have set the FFOptions with ExtensionOverrides = null, so this if (GlobalFFOptions.Current.ExtensionOverrides.ContainsKey(Name)) will get exception.

after i remove this ExtensionOverrides = null, the FFMpeg.Snapshot(which has called FileExtension.Png) method work well
image

If you for some reason still wanted to set ExtensionOverrides to null, your conditional could be updated to

if (GlobalFFOptions.Current.ExtensionOverrides?.ContainsKey(Name) == true)

Ah, I see, that's a check by this library, here:

if (GlobalFFOptions.Current.ExtensionOverrides.ContainsKey(Name))

Might be worth a PR