-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFFmpegLoader.cs
More file actions
135 lines (116 loc) · 4.43 KB
/
FFmpegLoader.cs
File metadata and controls
135 lines (116 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
namespace FFmpeg.AutoGen.Toolkit
{
using System;
using System.IO;
using System.Runtime.InteropServices;
using FFmpeg.AutoGen.Toolkit.Interop;
using FFmpeg.AutoGen.Abstractions;
/// <summary>
/// Contains methods for managing FFmpeg libraries.
/// </summary>
public static class FFmpegLoader
{
private static LogLevel logLevel = LogLevel.Error;
private static bool isPathSet;
/// <summary>
/// Delegate for log message callback.
/// </summary>
/// <param name="message">The message.</param>
public delegate void LogCallbackDelegate(string message);
/// <summary>
/// Log message callback event.
/// </summary>
public static event LogCallbackDelegate LogCallback;
/// <summary>
/// Gets or sets the verbosity level of FFMpeg logs printed to standard error/output.
/// Default value is <see cref="LogLevel.Error"/>.
/// </summary>
public static LogLevel LogVerbosity
{
get => logLevel;
set
{
if (IsFFmpegLoaded)
{
ffmpeg.av_log_set_level((int)value);
}
logLevel = value;
}
}
/// <summary>
/// Gets the FFmpeg version info string.
/// Empty when FFmpeg libraries were not yet loaded.
/// </summary>
public static string FFmpegVersion { get; private set; } = string.Empty;
/// <summary>
/// Gets a value indicating whether the loaded FFmpeg binary files are licensed under the GPL.
/// Null when FFmpeg libraries were not yet loaded.
/// </summary>
public static bool? IsFFmpegGplLicensed { get; private set; }
/// <summary>
/// Gets the FFmpeg license text
/// Empty when FFmpeg libraries were not yet loaded.
/// </summary>
public static string FFmpegLicense { get; private set; } = string.Empty;
/// <summary>
/// Gets a value indicating whether the FFmpeg binary files were successfully loaded.
/// </summary>
internal static bool IsFFmpegLoaded { get; private set; }
//public static void LoadFFmpeg()
//{
// if (IsFFmpegLoaded)
// {
// return;
// }
// if (!isPathSet)
// {
// try
// {
// FFmpegPath = NativeMethods.GetFFmpegDirectory();
// }
// catch (DirectoryNotFoundException)
// {
// throw new DirectoryNotFoundException("Cannot found the default FFmpeg directory.\n" +
// "On Windows you have to set \"FFmpegLoader.FFmpegPath\" with full path to the directory containing FFmpeg 5.x shared build \".dll\" files\n" +
// "For more informations please see https://github.com/radek-k/FFmpeg.AutoGen.Toolkit#setup");
// }
// }
// try
// {
// FFmpegVersion = ffmpeg.av_version_info();
// FFmpegLicense = ffmpeg.avcodec_license();
// IsFFmpegGplLicensed = FFmpegLicense.StartsWith("GPL");
// }
// catch (DllNotFoundException ex)
// {
// HandleLibraryLoadError(ex);
// }
// catch (NotSupportedException ex)
// {
// HandleLibraryLoadError(ex);
// }
// IsFFmpegLoaded = true;
// LogVerbosity = logLevel;
//}
/// <summary>
/// Start logging ffmpeg output.
/// </summary>
public static unsafe void SetupLogging()
{
ffmpeg.av_log_set_level(ffmpeg.AV_LOG_VERBOSE);
// do not convert to local function
av_log_set_callback_callback logCallback = (p0, level, format, vl) =>
{
if (level > ffmpeg.av_log_get_level())
return;
var lineSize = 1024;
var lineBuffer = stackalloc byte[lineSize];
var printPrefix = 1;
ffmpeg.av_log_format_line(p0, level, format, vl, lineBuffer, lineSize, &printPrefix);
var line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer);
LogCallback?.Invoke(line);
};
ffmpeg.av_log_set_callback(logCallback);
}
}
}