Skip to content

Commit

Permalink
add display capture offset options
Browse files Browse the repository at this point in the history
  • Loading branch information
adryzz committed Oct 28, 2022
1 parent 3d27894 commit 93c4229
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
22 changes: 20 additions & 2 deletions SeeShark/Device/DisplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@ public DisplayManager(DeviceInputFormat? inputFormat = null) : base(inputFormat
{
}

public override Display GetDevice(DisplayInfo info, VideoInputOptions? options = null) =>
new Display(info, InputFormat, options);
public override Display GetDevice(DisplayInfo info, VideoInputOptions? options = null)
{
if (options is { } o)
{
return new Display(info, InputFormat, o);
}
else
{
return new Display(info, InputFormat, generateInputOptions(info));
}
}

private VideoInputOptions generateInputOptions(DisplayInfo info)
{
return new VideoInputOptions
{
VideoSize = (info.Width, info.Height),
VideoPosition = (info.X, info.Y)
};
}

/// <summary>
/// Enumerates available devices.
Expand Down
2 changes: 1 addition & 1 deletion SeeShark/Device/VideoDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class VideoDevice : Disposable
public VideoDevice(VideoDeviceInfo info, DeviceInputFormat inputFormat, VideoInputOptions? options = null)
{
Info = info;
decoder = new VideoStreamDecoder(info.Path, inputFormat, options?.ToAVDictOptions());
decoder = new VideoStreamDecoder(info.Path, inputFormat, options?.ToAVDictOptions(inputFormat));
}

protected void DecodeLoop()
Expand Down
27 changes: 26 additions & 1 deletion SeeShark/VideoInputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using FFmpeg.AutoGen;
using SeeShark.Device;

namespace SeeShark
{
Expand All @@ -27,6 +28,12 @@ public class VideoInputOptions
/// </remarks>
/// <value>(width, height)</value>
public (int, int)? VideoSize { get; set; }

/// <summary>
/// To request the capture to start from a specific point
/// </summary>
/// <value>(x, y)</value>
public (int, int)? VideoPosition { get; set; }
/// <summary>
/// To request a specific framerate for the video stream.
/// </summary>
Expand All @@ -42,7 +49,7 @@ public class VideoInputOptions
/// <summary>
/// Combines all properties into a dictionary of options that FFmpeg can use.
/// </summary>
public virtual IDictionary<string, string> ToAVDictOptions()
public virtual IDictionary<string, string> ToAVDictOptions(DeviceInputFormat? inputFormat = null)
{
Dictionary<string, string> dict = new();

Expand All @@ -56,6 +63,24 @@ public virtual IDictionary<string, string> ToAVDictOptions()
if (InputFormat != null)
dict.Add("input_format", InputFormat);

if (VideoPosition != null)
{
switch (inputFormat)
{
case DeviceInputFormat.X11Grab:
{
dict.Add("grab_x", VideoPosition.Value.Item1.ToString());
dict.Add("grab_y", VideoPosition.Value.Item2.ToString());
break;
}
case DeviceInputFormat.GdiGrab:
{
dict.Add("offset_x", VideoPosition.Value.Item1.ToString());
dict.Add("offset_y", VideoPosition.Value.Item2.ToString());
break;
}
}
}
return dict;
}
}
Expand Down

0 comments on commit 93c4229

Please sign in to comment.