-
Notifications
You must be signed in to change notification settings - Fork 187
In C# .Net 8 MediaInfo_Count_Get cant get value in release version? #2210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The following code works on both debug and release: using System.Runtime.InteropServices;
string path = "Test.m2ts";
using (MediaInfo mi = new MediaInfo(path))
{
string summary = mi.GetSummary(true, false);
int videoCount = mi.GetCount(MediaInfoStreamKind.Video);
int audioCount = mi.GetCount(MediaInfoStreamKind.Audio);
string fps = mi.GetVideo(0, "FrameRate");
Console.WriteLine(summary);
Console.WriteLine($"fps:{fps} videoCount:{videoCount} audioCount:{audioCount}");
}
public class MediaInfo : IDisposable
{
readonly IntPtr Handle;
public MediaInfo(string file)
{
if ((Handle = MediaInfo_New()) == IntPtr.Zero)
throw new Exception("Failed to call MediaInfo_New");
if (MediaInfo_Open(Handle, file) == 0)
throw new Exception("Error MediaInfo_Open");
}
public string GetInfo(MediaInfoStreamKind kind, string parameter)
{
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, kind, 0,
parameter, MediaInfoKind.Text, MediaInfoKind.Name)) ?? "";
}
public int GetCount(MediaInfoStreamKind kind) => MediaInfo_Count_Get(Handle, kind, -1);
public string GetGeneral(string parameter)
{
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.General,
0, parameter, MediaInfoKind.Text, MediaInfoKind.Name)) ?? "";
}
public string GetVideo(int stream, string parameter)
{
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Video,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name)) ?? "";
}
public string GetAudio(int stream, string parameter)
{
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Audio,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name)) ?? "";
}
public string GetText(int stream, string parameter)
{
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Text,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name)) ?? "";
}
public string GetSummary(bool complete, bool rawView)
{
MediaInfo_Option(Handle, "Language", rawView ? "raw" : "");
MediaInfo_Option(Handle, "Complete", complete ? "1" : "0");
return Marshal.PtrToStringUni(MediaInfo_Inform(Handle, 0)) ?? "";
}
bool Disposed;
public void Dispose()
{
if (!Disposed)
{
if (Handle != IntPtr.Zero)
{
MediaInfo_Close(Handle);
MediaInfo_Delete(Handle);
}
Disposed = true;
GC.SuppressFinalize(this);
}
}
~MediaInfo() { Dispose(); }
[DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_New();
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern int MediaInfo_Open(IntPtr handle, string path);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern IntPtr MediaInfo_Option(IntPtr handle, string option, string value);
[DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_Inform(IntPtr handle, IntPtr reserved);
[DllImport("MediaInfo.dll")]
static extern int MediaInfo_Close(IntPtr handle);
[DllImport("MediaInfo.dll")]
static extern void MediaInfo_Delete(IntPtr handle);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern IntPtr MediaInfo_Get(IntPtr handle, MediaInfoStreamKind kind,
IntPtr stream, string parameter, MediaInfoKind infoKind, MediaInfoKind searchKind);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern int MediaInfo_Count_Get(IntPtr handle, MediaInfoStreamKind streamKind, IntPtr stream);
}
public enum MediaInfoStreamKind
{
General,
Video,
Audio,
Text,
Other,
Image,
Menu,
Max,
}
public enum MediaInfoKind
{
Name,
Text,
Measure,
Options,
NameText,
MeasureText,
Info,
HowTo
} Output:
|
@cjee21 Thx for help,Now it is working fine! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dll version: MediaInfo_DLL_24.12_Windows_x64_WithoutInstaller
MediaInfo_Inform can get inform
MediaInfo_Get can get stream inform
MediaInfo_Count_Get can return count in debug mode
but MediaInfo_Count_Get always return 0 in release version?
The text was updated successfully, but these errors were encountered: