I am trying to build a demo C# project using the openh264 library from Cisco.
I have a very basic setup. Here is the .sln file
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "h264", "h264\h264.csproj", "{C9FA208E-5506-441B-9837-FB5469B950FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9FA208E-5506-441B-9837-FB5469B950FA}.Debug|x86.ActiveCfg = Debug|x86
{C9FA208E-5506-441B-9837-FB5469B950FA}.Debug|x86.Build.0 = Debug|x86
{C9FA208E-5506-441B-9837-FB5469B950FA}.Release|x86.ActiveCfg = Release|x86
{C9FA208E-5506-441B-9837-FB5469B950FA}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
The project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="openh264">
<HintPath>openh264-2.3.1-win32.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
While the Program.cs file looks like this:
using System.Runtime.InteropServices;
public class h264Demo {
[DllImport("openh264-2.3.1-win32.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int WelsCreateSVCEncoder();
public static void Main() {
Console.WriteLine("Hello h264 demo");
int result = WelsCreateSVCEncoder();
Console.WriteLine("Result is: {0}",result);
}
}
It is what I could find using the dumpbin
utility.
C:\Users\Admin\source\repos\h264Demo\h264>dumpbin /exports openh264-2.3.1-win32.dll
Microsoft (R) COFF/PE Dumper Version 14.33.31630.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file openh264-2.3.1-win32.dll
File Type: DLL
Section contains the following exports for openh264.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
6 number of functions
6 number of names
ordinal hint RVA name
1 0 0007DDD0 WelsCreateDecoder
2 1 00049D60 WelsCreateSVCEncoder
3 2 0007DE20 WelsDestroyDecoder
4 3 00049DA0 WelsDestroySVCEncoder
5 4 00049DC0 WelsGetCodecVersion
6 5 00049DC0 WelsGetCodecVersionEx
Summary
2000 .data
1B000 .rdata
4000 .reloc
2000 .rodata
1000 .rsrc
A1000 .text
When I build I get the following warnings:
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. System.BadImageFormatException: PE image does not have metadata. [C:\Users\Admin\source\repos\h264Demo\h264\h264.csproj]
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3246: at System.Reflection.Metadata.MetadataReader.GetAssemblyName(String assemblyFile) [C:\Users\Admin\source\repos\h264Demo\h264\h264.csproj]
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3246: at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path) [C:\Users\Admin\source\repos\h264Demo\h264\h264.csproj]
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3246: at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path) [C:\Users\Admin\source\repos\h264Demo\h264\h264.csproj]
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3246: at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryAssemblyReferenceItem(ITaskItem referenceAssemblyName) [C:\Users\Admin\source\repos\h264Demo\h264\h264.csproj]
subsequently when I execute the resulted executable I receive:
$ ./h264.exe
Hello h264 demo
Fatal error. 0xC0000005
at h264Demo.WelsCreateSVCEncoder()
at h264Demo.Main()
Segmentation fault
When I tried the Openh264Lib.net project suggested here I could use the library.
However I cannot understand why my solution does not work. The openh264 binaries are the official ones.