forked from sipsorcery-org/sipsorcery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFmpegScreenSource.cs
More file actions
66 lines (59 loc) · 2.44 KB
/
FFmpegScreenSource.cs
File metadata and controls
66 lines (59 loc) · 2.44 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
using FFmpeg.AutoGen;
using Microsoft.Extensions.Logging;
using SIPSorceryMedia.Abstractions;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace SIPSorceryMedia.FFmpeg
{
public class FFmpegScreenSource : FFmpegVideoSource
{
private static ILogger logger = SIPSorcery.LogFactory.CreateLogger<FFmpegScreenSource>();
public unsafe FFmpegScreenSource(string path, Rectangle rect, int frameRate = 20)
{
string inputFormat;
Dictionary<String, String>? options = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
inputFormat = "gdigrab";
options = new Dictionary<string, string>()
{
["offset_x"] = rect.X.ToString(),
["offset_y"] = rect.Y.ToString(),
["video_size"] = $"{rect.Width}X{rect.Height}",
["framerate"] = frameRate.ToString()
};
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
inputFormat = "avfoundation";
options = new Dictionary<string, string>()
{
["vf"] = $"crop={rect.Width}:{rect.Height}:{rect.X}:{rect.Y}",
["framerate"] = frameRate.ToString()
};
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
inputFormat = "x11grab";
//https://superuser.com/questions/1562228/how-to-specify-the-size-to-record-the-screen-with-ffmpeg
options = new Dictionary<string, string>()
{
["video_size"] = $"{rect.Width}X{rect.Height}",
["grab_x"] = rect.X.ToString(),
["grab_y"] = rect.Y.ToString(),
["framerate"] = frameRate.ToString()
};
}
else
throw new NotSupportedException($"Cannot find adequate input format - OSArchitecture:[{RuntimeInformation.OSArchitecture}] - OSDescription:[{RuntimeInformation.OSDescription}]");
AVInputFormat* aVInputFormat = ffmpeg.av_find_input_format(inputFormat);
CreateVideoDecoder(path, aVInputFormat, false, true);
InitialiseDecoder(options);
}
}
}