Using the C#, C++ and Python Wrappers
C# Wrapper
The C# wrapper is used to access all the methods of TFBRecorder. To use the wrapper:
- Import the file FBRecorder.cs into your project folder. The file is located in the “C# Wrapper” folder in the SDK install folder.
- Import the SDK DLL – fbrecorder.dll – file into your project. The file is located in the SDK install folder. In Visual studio, you would drag the DLL into References in the Solution Explorer:
- Click on the DLL file and set to always copy to the output directory. In Visual Studio this option looks like:
- To access the methods import the FBRecorder namespace with the using directive: using FBRecorder.
Usage:
For an example of how to use the C# wrapper, see the folder /Samples/C# in the SDK install folder.
using FBRecorder;
static void PrintGlobalErrors(TFBRecorder pRecorderObject) {
int iErrorIndex = 0;
while (true) {
TFBRecorder.TFBGlobalErrors Error = pRecorderObject.GetGlobalError(iErrorIndex);
if (Error == TFBRecorder.TFBGlobalErrors.Unknown)
break;
Console.WriteLine("Error: " + Error);
iErrorIndex++;
}
}
string logFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FBRecorderTestCS");
TFBRecorder pRecorderObject = new TFBRecorder("",logFolder, 10, TFBRecorder.TLogKind.Verbose);
if(!pRecorderObject.CanUse()) {
Console.WriteLine("Error: unable to create a recorder object.");
goto end_of_func;
}
pRecorderObject.ActivateProfile(TFBRecorder.TFBRecorderProfiles.SAFE_SCREEN_MIC_VIDEOCAPTURE);
if (!pRecorderObject.InitRecorder("d:\\test.mp4")) {
Console.WriteLine("Error: unable to init recorder.");
PrintGlobalErrors(pRecorderObject);
goto end_of_func;
}
PrintGlobalErrors(pRecorderObject);
pRecorderObject.ResetGlobalErrors();
if (!pRecorderObject.StartRecording()) {
PrintGlobalErrors(pRecorderObject);
Console.WriteLine("Error: unable to start the recording.");
goto end_of_func;
}
PrintGlobalErrors(pRecorderObject);
Console.WriteLine("Recording... To stop the recording press Esc...");
while (true) {
if (Console.ReadKey().Key == ConsoleKey.Escape)
break;
}
Console.WriteLine("Stopping the recording...");
pRecorderObject.StopRecording();
C++ Wrapper
The C++ wrapper consists of two files: FBRecorder.h and FBRecorder.cpp, both included in the “C++ Wrapper” folder in the SDK install folder.
- Use the #include directive to include the file FBRecorder.h in your project.
- Add FBRecorder.cpp to the Source Files for your project in Visual Studio.
- Include a JSON parser in your project. We recommend: https://github.com/nbsdx/SimpleJSON
Usage:
For an example of how to use the C++ wrapper, see the folder /Samples/C++ in the SDK install folder.
std::unique_ptr pFBRecorder(new FBRecorder::TFBRecorder(wsPathToFBRecorderDLL,"",wsLogFolder, 10, FBRecorder::TLogKind::Verbose));
if (!pFBRecorder->CanUse()) {
printf("Error: unable to use a recorder wrapper.\n");
goto end_of_func;
}
// Activate a profile:
pFBRecorder->ActivateProfile(TFBRecorderProfile::SAFE_SCREEN);
// Start a recording: pFBRecorder->ResetGlobalErrors();
if (!pFBRecorder->InitRecorder(wsMP4Filename)) {
printf("Error: unable to init recorder.\n");
PrintGlobalErrors(pFBRecorder.get()); goto end_of_func;
}
PrintGlobalErrors(pFBRecorder.get());
pFBRecorder->ResetGlobalErrors();
if (!pFBRecorder->StartRecording()) {
printf("Error: unable to start the recording.\n");
PrintGlobalErrors(pFBRecorder.get());
goto end_of_func;
}
PrintGlobalErrors(pFBRecorder.get());
...
// Stop the recording:
pFBRecorder->StopRecording();
Python Wrapper
The python wrapper consists of one file: ‘FBRecorder.py’, included in the “Python Wrapper” folder in the SDK install folder. The file should be copied into your host application folder or any other accessible folder.
To use the wrapper, include in your python project:
from FBRecorder import FBRecorder, LogKind, FBRecorderProfile, FBGlobalError
When constructing the FBRecorder instance, an additional parameter is required – the path to the FBRecorder.dll file:
class FBRecorder:
#dll_full_path - path to FBRecorder.dll
#log_full_path can be None or empty if the log is not required
#log_kind - from the LogKind enumeration class
def __init__(self, dll_full_path, license_string, log_full_path, log_folder_size_mb, log_kind) -> None:
The first parameter to the constructor must be a string containing a full path to the FBRecorder.dll. If the path to the dll is in the global PATH environment variable or the dll is in the host app folder, then only the dll name should be supplied (‘FBRecorder.dll’).
Example:
from FBRecorder import FBRecorder, LogKind, FBRecorderProfile, FBGlobalError, FBRecorderImageFormat
fbRecorder = FBRecorder("C:\\sdk_install_folder\\FBRecorder.dll",
"",
"C:\\folder_for_log_files\\",
32,
LogKind.Verbose)
Note: GetDefaultConfigJSON and GetConfigJSONForProfile methods return a tuple <bool, string>. ‘bool’ is a function result and a ‘string’ is a json string.
Usage:
For an example of how to use the Python wrapper, see the folder /Samples/Python in the SDK install folder.
# First, define a function to print the global errors
def PrintGlobalErrors(pFBRecorder):
ErrorIndex = 0
while True:
Error = pFBRecorder.GetGlobalError(ErrorIndex)
if Error == FBGlobalError.Unknown:
break
print("Global error: %d" % (Error.value))
ErrorIndex += 1
fbRecorder = FBRecorder("C:\\sdk_install_folder\\FBRecorder.dll",
"",
"C:\\folder_for_log_files\\",
32,
LogKind.Verbose)
if not fbRecorder.CreateRecorder():
print("Unable to create FBRecorder")
exit(0)
# List the available video encoders. First get the default configuration as a JSON object
bresult, sjsonconfig = fbRecorder.GetDefaultConfigJSON()
if not bresult:
print("fbRecorder.GetDefaultConfigJSON error")
exit(0)
jsonconfig = json.loads(sjsonconfig)
print("Existing video encoders:")
# Iterate through the items in AvailableVideoEncoders and print their names
for video_encoder in jsonconfig['AvailableVideoEncoders']:
if fbRecorder.CheckVideoEncoderAvailability(video_encoder['Type'], video_encoder['Name']):
print(video_encoder)
# Use the SAFE_SCREEN profile for recording
if not fbRecorder.ActivateProfile(FBRecorderProfile.SAFE_SCREEN):
print("fbRecorder.ActivateProfile error")
exit(0)
fbRecorder.ResetGlobalErrors()
if not fbRecorder.InitRecorder('d:\\test.mp4'):
print("fbRecorder.InitRecorder error")
PrintGlobalErrors(fbRecorder)
exit(0)
PrintGlobalErrors(fbRecorder)
fbRecorder.ResetGlobalErrors()
if not fbRecorder.StartRecording():
print("fbRecorder.StartRecording error")
PrintGlobalErrors(fbRecorder)
exit(0)
PrintGlobalErrors(fbRecorder)
print("recording for 10 secs...")
time.sleep(10)
fbRecorder.StopRecording()
print("recording has been stopped")
fbRecorder.DestroyRecorder()
print("Exit")