forked from akon47/ScreenRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaEncoder.cpp
More file actions
69 lines (64 loc) · 2.78 KB
/
Copy pathMediaEncoder.cpp
File metadata and controls
69 lines (64 loc) · 2.78 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
#include "pch.h"
#include "MediaEncoder.h"
namespace MediaEncoder
{
array<String^>^ MediaFormat::GetAllFormatLongNames()
{
auto ret = gcnew List<String^>();
const AVOutputFormat* fmt = nullptr;
void* i = nullptr;
while ((fmt = av_muxer_iterate(&i)))
{
ret->Add(gcnew String(fmt->long_name));
ret->Add(gcnew String(fmt->name));
}
return ret->Count > 0 ? ret->ToArray() : nullptr;
}
String^ MediaFormat::GetFormatExtensions(String^ format)
{
IntPtr formatStringPointer = Runtime::InteropServices::Marshal::StringToHGlobalUni(format);
auto nativeFormatUnicode = static_cast<wchar_t*>(formatStringPointer.ToPointer());
int utf8FormatStringSize = WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nullptr, 0, nullptr,
nullptr);
auto nativeFormat = new char[utf8FormatStringSize];
WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nativeFormat, utf8FormatStringSize, nullptr, nullptr);
const AVOutputFormat* fmt = av_guess_format(nativeFormat, nullptr, nullptr);
if (fmt != nullptr)
return gcnew String(fmt->extensions);
return nullptr;
}
String^ MediaFormat::GetFormatLongName(String^ format)
{
IntPtr formatStringPointer = Runtime::InteropServices::Marshal::StringToHGlobalUni(format);
auto nativeFormatUnicode = static_cast<wchar_t*>(formatStringPointer.ToPointer());
int utf8FormatStringSize = WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nullptr, 0, nullptr,
nullptr);
auto nativeFormat = new char[utf8FormatStringSize];
WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nativeFormat, utf8FormatStringSize, nullptr, nullptr);
const AVOutputFormat* fmt = av_guess_format(nativeFormat, nullptr, nullptr);
if (fmt != nullptr)
return gcnew String(fmt->long_name);
return nullptr;
}
void MediaFormat::GetFormatInfo(String^ format, [Runtime::InteropServices::Out] String^% longName,
[Runtime::InteropServices::Out] String^% extensions)
{
IntPtr formatStringPointer = Runtime::InteropServices::Marshal::StringToHGlobalUni(format);
auto nativeFormatUnicode = static_cast<wchar_t*>(formatStringPointer.ToPointer());
int utf8FormatStringSize = WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nullptr, 0, nullptr,
nullptr);
auto nativeFormat = new char[utf8FormatStringSize];
WideCharToMultiByte(CP_UTF8, 0, nativeFormatUnicode, -1, nativeFormat, utf8FormatStringSize, nullptr, nullptr);
const AVOutputFormat* fmt = av_guess_format(nativeFormat, nullptr, nullptr);
if (fmt != nullptr)
{
longName = gcnew String(fmt->long_name);
extensions = gcnew String(fmt->extensions);
}
else
{
longName = nullptr;
extensions = nullptr;
}
}
}