From 1f12d6779a15a6a1377b77958aa27f00687aaf82 Mon Sep 17 00:00:00 2001 From: Speykious Date: Sat, 19 Feb 2022 04:30:37 +0100 Subject: [PATCH] Prepare v3 (#24) * Better not leak memory there * Update `FFmpeg.AutoGen` * Update `PixelFormat` * Update Readme --- Readme.md | 15 ++-- .../SeeShark.Example.Ascii.csproj | 2 +- SeeShark/Decode/VideoStreamDecoder.cs | 1 + SeeShark/PixelFormat.cs | 70 +++++++++++++------ SeeShark/SeeShark.csproj | 2 +- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/Readme.md b/Readme.md index 9ad51d5..6ff3ba6 100644 --- a/Readme.md +++ b/Readme.md @@ -1,12 +1,12 @@ # SeeShark -> Simple C# camera library. +> Simple C# camera and display library. [![Discord](https://img.shields.io/discord/871618277258960896?color=7289DA&label=%20&logo=discord&logoColor=white)](https://discord.gg/Tz96ZdKjSA) ![NuGet](https://img.shields.io/nuget/v/SeeShark) When you SeeShark, you C#! -SeeShark is a simple cross-platform .NET library for handling camera inputs on Linux, Windows and MacOS. +SeeShark is a simple cross-platform .NET library for handling camera and screen display inputs on Linux, Windows and MacOS. Using FFmpeg, it allows you to enumerate camera devices and decode raw frames in 199 different pixel formats (because that's how powerful FFmpeg is!). @@ -14,18 +14,19 @@ Features include: - Zero-copy. - Memory-safe. - Cross platform (Tested on Windows and Linux, might work on more platforms like MacOS). -- Managing camera devices. +- Managing camera and display devices. +- Control framerate, resolution and input format. - Notifies the application if devices get connected/disconnected. -- Event-driven code flow. -- Supports 199 different pixel formats. +- Provides synchronous (method-driven) and asynchronous (event-driven) code flow. +- Supports 206 different pixel formats. - Conversion of a frame from a pixel format to another. - Scaling frames. - Access to raw pixel data. Features **don't** include: - Saving a frame as an image (here's a [wiki page on how to do it](https://github.com/vignetteapp/SeeShark/wiki/Saving-images) using ImageSharp). -- Recording a camera stream to a video file. -- Manage audio devices. +- Recording a video stream to a video file. +- Managing audio devices. *** diff --git a/SeeShark.Example.Ascii/SeeShark.Example.Ascii.csproj b/SeeShark.Example.Ascii/SeeShark.Example.Ascii.csproj index 5afc0e6..33c9bc6 100644 --- a/SeeShark.Example.Ascii/SeeShark.Example.Ascii.csproj +++ b/SeeShark.Example.Ascii/SeeShark.Example.Ascii.csproj @@ -8,7 +8,7 @@ - + diff --git a/SeeShark/Decode/VideoStreamDecoder.cs b/SeeShark/Decode/VideoStreamDecoder.cs index 084e93e..2d8c790 100644 --- a/SeeShark/Decode/VideoStreamDecoder.cs +++ b/SeeShark/Decode/VideoStreamDecoder.cs @@ -53,6 +53,7 @@ public VideoStreamDecoder(string url, AVInputFormat* inputFormat = null, IDictio } ffmpeg.avformat_open_input(&formatContext, url, inputFormat, &dict).ThrowExceptionIfError(); + ffmpeg.av_dict_free(&dict); AVCodec* codec = null; StreamIndex = ffmpeg diff --git a/SeeShark/PixelFormat.cs b/SeeShark/PixelFormat.cs index ad16b06..0f484a0 100644 --- a/SeeShark/PixelFormat.cs +++ b/SeeShark/PixelFormat.cs @@ -70,19 +70,19 @@ public enum PixelFormat : int /// planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P /// and setting color_range /// - [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV420P")] + [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range")] Yuvj420P = AVPixelFormat.AV_PIX_FMT_YUVJ420P, /// /// planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P /// and setting color_range /// - [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV422P")] + [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range")] Yuvj422P = AVPixelFormat.AV_PIX_FMT_YUVJ422P, /// /// planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P /// and setting color_range /// - [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV444P")] + [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range")] Yuvj444P = AVPixelFormat.AV_PIX_FMT_YUVJ444P, /// /// packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 @@ -159,7 +159,7 @@ public enum PixelFormat : int /// planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P /// and setting color_range /// - [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV440P")] + [Obsolete("Deprecated in favor of AV_PIX_FMT_YUV440P and setting color range")] Yuvj440P = AVPixelFormat.AV_PIX_FMT_YUVJ440P, /// /// planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) @@ -208,22 +208,7 @@ public enum PixelFormat : int /// Bgr555Le = AVPixelFormat.AV_PIX_FMT_BGR555LE, /// - /// HW acceleration through VA API at motion compensation entry-point, Picture.data[3] - /// contains a vaapi_render_state struct which contains macroblocks as well as various - /// fields extracted from headers - /// - VaapiMoco = AVPixelFormat.AV_PIX_FMT_VAAPI_MOCO, - /// - /// HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains - /// a vaapi_render_state struct which contains fields extracted from headers - /// - VaapiIdct = AVPixelFormat.AV_PIX_FMT_VAAPI_IDCT, - /// - /// HW decoding through VA API, Picture.data[3] contains a VASurfaceID - /// - VaapiVld = AVPixelFormat.AV_PIX_FMT_VAAPI_VLD, - /// - /// alias for VaapiVld + /// Hardware acceleration through VA-API, data[3] contains a VASurfaceID. /// Vaapi = AVPixelFormat.AV_PIX_FMT_VAAPI, /// @@ -345,6 +330,7 @@ public enum PixelFormat : int /// Gbrp = AVPixelFormat.AV_PIX_FMT_GBRP, /// + /// alias for GBRP /// Gbr24P = AVPixelFormat.AV_PIX_FMT_GBR24P, /// @@ -544,7 +530,7 @@ public enum PixelFormat : int /// /// packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined /// - ZeroRgb = AVPixelFormat.AV_PIX_FMT_0RGB, + Xrgb = AVPixelFormat.AV_PIX_FMT_0RGB, /// /// packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined /// @@ -859,10 +845,50 @@ public enum PixelFormat : int /// X2Rgb10Be = AVPixelFormat.AV_PIX_FMT_X2RGB10BE, /// + /// packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), little-endian, X=unused/undefined + /// + X2Bgr10Le = AVPixelFormat.AV_PIX_FMT_X2BGR10LE, + /// + /// packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), big-endian, X=unused/undefined + /// + X2Bgr10Be = AVPixelFormat.AV_PIX_FMT_X2BGR10BE, + /// + /// interleaved chroma YUV 4:2:2, 20bpp, data in the high bits, big-endian + /// + P210Be = AVPixelFormat.AV_PIX_FMT_P210BE, + /// + /// interleaved chroma YUV 4:2:2, 20bpp, data in the high bits, little-endian + /// + P210Le = AVPixelFormat.AV_PIX_FMT_P210LE, + /// + /// interleaved chroma YUV 4:4:4, 30bpp, data in the high bits, big-endian + /// + P410Be = AVPixelFormat.AV_PIX_FMT_P410BE, + /// + /// interleaved chroma YUV 4:4:4, 30bpp, data in the high bits, little-endian + /// + P410Le = AVPixelFormat.AV_PIX_FMT_P410LE, + /// + /// interleaved chroma YUV 4:2:2, 32bpp, big-endian + /// + P216Be = AVPixelFormat.AV_PIX_FMT_P216BE, + /// + /// interleaved chroma YUV 4:2:2, 32bpp, liddle-endian + /// + P216Le = AVPixelFormat.AV_PIX_FMT_P216LE, + /// + /// interleaved chroma YUV 4:4:4, 48bpp, big-endian + /// + P416Be = AVPixelFormat.AV_PIX_FMT_P416BE, + /// + /// interleaved chroma YUV 4:4:4, 48bpp, little-endian + /// + P416Le = AVPixelFormat.AV_PIX_FMT_P416LE, + /// /// number of pixel formats, DO NOT USE THIS if you want to link with shared libav* /// because the number of formats might differ between versions /// - AvPixFmtNb = AVPixelFormat.AV_PIX_FMT_NB + Nb = AVPixelFormat.AV_PIX_FMT_NB } public static class PixelFormatExtensions diff --git a/SeeShark/SeeShark.csproj b/SeeShark/SeeShark.csproj index 9274c62..b92b128 100644 --- a/SeeShark/SeeShark.csproj +++ b/SeeShark/SeeShark.csproj @@ -25,7 +25,7 @@ - +