From a5a7a1cd9dc5517ad3313897827f62472cac1630 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:59:52 -0800 Subject: [PATCH 1/4] Refactor pixel format property to be nullable. --- src/AllenNeuralDynamics.Core/AindSpinnakerCapture.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/AllenNeuralDynamics.Core/AindSpinnakerCapture.cs b/src/AllenNeuralDynamics.Core/AindSpinnakerCapture.cs index c465b2d..2f26981 100644 --- a/src/AllenNeuralDynamics.Core/AindSpinnakerCapture.cs +++ b/src/AllenNeuralDynamics.Core/AindSpinnakerCapture.cs @@ -32,20 +32,23 @@ public AindSpinnakerCapture() [Description("Parameter used for gamma correction. If null, gamma correction is disabled.")] public double? Gamma { get; set; } - [Description("Sensor pixel format.")] - public PixelFormatEnums PixelFormat { get; set; } + [Description("Sensor pixel format. If null, the currently set value in the camera will be used.")] + public PixelFormatEnums? PixelFormat { get; set; } [Description("Region of interest to crop the sensor with.")] public Rect RegionOfInterest { get; set; } = new Rect(0,0,0,0); - [Description("Sensor ADC bit depth used to acquired data.")] + [Description("Sensor ADC bit depth used to acquired data. If null the currently set value in the camera will be used.")] public AdcBitDepthEnums? AdcBitDepth { get; set; } protected override void Configure(IManagedCamera camera) { try { camera.AcquisitionStop.Execute(); } catch { } - camera.PixelFormat.Value = PixelFormat.ToString(); + if (PixelFormat.HasValue) + { + camera.PixelFormat.Value = PixelFormat.Value.ToString(); + } if (AdcBitDepth.HasValue) { camera.AdcBitDepth.Value = AdcBitDepth.Value.ToString(); From b92a87d5cd0feb94e4a2bdcfd9c2e6cde40b404a Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:57:23 -0800 Subject: [PATCH 2/4] Infer pixel format from input Mat --- src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs b/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs index 0cad6d6..8acb2a0 100644 --- a/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs +++ b/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs @@ -51,13 +51,20 @@ public override IObservable Process(IObservable source) var writer = new ImageWriter { Path = pipe }; return writer.Process(ps).Merge(ps.Take(1).Delay(TimeSpan.FromSeconds(1)).SelectMany(image => { + string pixelFormat; + if (image.Channels == 1 && image.Depth==IplDepth.U8) pixelFormat = "gray"; + else if (image.Channels == 3 && image.Depth == IplDepth.U8) pixelFormat = "bgr24"; + else if (image.Channels == 1 && image.Depth == IplDepth.U16) pixelFormat = "gray16le"; + else if (image.Channels == 3 && image.Depth == IplDepth.U16) pixelFormat = "bgr48le"; + else throw new InvalidOperationException(string.Format("Unsupported image format. Got {0} channels and depth {1}", image.Channels, image.Depth)); + var inputArguments = string.Format("-v {0} {1}", Verbosity.ToString().ToLower(), InputArguments); var args = string.Format("-f rawvideo -vcodec rawvideo {0}-s {1}x{2} -r {3} -pix_fmt {4} {5} -i {6} {7} {8}", overwrite ? "-y " : string.Empty, image.Width, image.Height, FrameRate, - image.Channels == 1 ? "gray" : "bgr24", + pixelFormat, inputArguments, pipe, OutputArguments, From 9e5a7cd944f0987840716e246f0abb083426b037 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:20:29 -0800 Subject: [PATCH 3/4] Bump package --- src/AllenNeuralDynamics.Core/AllenNeuralDynamics.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AllenNeuralDynamics.Core/AllenNeuralDynamics.Core.csproj b/src/AllenNeuralDynamics.Core/AllenNeuralDynamics.Core.csproj index 7c0735f..f3fc22c 100644 --- a/src/AllenNeuralDynamics.Core/AllenNeuralDynamics.Core.csproj +++ b/src/AllenNeuralDynamics.Core/AllenNeuralDynamics.Core.csproj @@ -9,7 +9,7 @@ Bonsai Rx Core AllenNeuralDynamics net472 strict - 0.2.8 + 0.2.9 From 5ebc780efc94c245b195cb4d07843d70218f3de7 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:00:15 -0800 Subject: [PATCH 4/4] Update codec as per https://github.com/AllenNeuralDynamics/Aind.Behavior.Services/pull/117 --- src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs b/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs index 8acb2a0..a9680f3 100644 --- a/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs +++ b/src/AllenNeuralDynamics.Core/FfmpegVideoWriter.cs @@ -29,7 +29,7 @@ public class FfmpegVideoWriter : Sink [Editor(DesignTypes.MultilineStringEditor, DesignTypes.UITypeEditor)] [Description("The optional set of command-line arguments to use for configuring the video codec.")] - public string OutputArguments { get; set; } = @"-vf ""scale=out_color_matrix=bt709:out_range=full"" -c:v h264_nvenc -pix_fmt nv12 -color_range full -colorspace bt709 -color_trc linear -tune hq -preset p4 -rc vbr -cq 12 -b:v 0M -metadata author=""Allen Institute for Neural Dynamics"" -maxrate 700M -bufsize 350M"; + public string OutputArguments { get; set; } = @"-vf ""scale=out_color_matrix=bt709:out_range=full:sws_dither=none,format=yuv420p10le,colorspace=ispace=bt709:all=bt709:dither=none,scale=out_range=tv:sws_dither=none,format=yuv420p"" -c:v libx264 -preset veryslow -crf 18 -pix_fmt yuv420p -metadata author=""Allen Institute for Neural Dynamics"" -movflags +faststart+write_colr"; [Editor(DesignTypes.MultilineStringEditor, DesignTypes.UITypeEditor)] [Description("The optional set of command-line arguments to use for configuring the input video stream.")]