MilestoneSystemsInc / PowerShellSamples

A collection of samples for managing your Milestone XProtect VMS using MilestonePSTools in PowerShell
https://www.milestonepstools.com
MIT License
36 stars 12 forks source link

Start-Export #114

Closed subbuun closed 6 months ago

subbuun commented 10 months ago

The below commend works great and faster than exporting from the Smart Client.

Is there a way to include the Time Stamp and create a single file like say 10 GB.

Start-Export -CameraIds $id -Format AVI -Codec -StartTime '2023-11-09 14:00:00' -EndTime '2023-11-09 15:00:00' -Path C:\Export -Name Sample -MaxAviSizeInBytes 512MB

Tarterman commented 10 months ago

The SDK supports including the timestamp but it hasn't been implemented in MilestonePSTools. Maybe it is something that @joshooaj can put on the todo list.

As for the file size, historically, AVI files have had a size limit of 2GB. That was increased to 4GB if it is switched to using DirectShow based software (which Milestone doesn't use) or if Milestone were to write their own software to handles the AVIs. Going above 4GB is only possible if the OpenDML 1.02 extension has been implemented. It basically takes a bunch of AVI files and bundles them as one AVI file.

All that to say that, at this point, AVI exports will split an export into separate AVI files if the export is larger than 2GB.

subbuun commented 9 months ago

Thanks. I have few more questions on the export as below.

  1. Is there a way to export in on ASF format or MKV format with the time stamp via the SDK to overcome the 2GB limit?
  2. I have installed the k-lite codec and would like to export via the x265vfw - H.264/MPEG-4 AVC codec. But it says Start-Export : The specified codec is not available.
joshooaj commented 9 months ago

Hi @subbuun,

MKV or AVI are the container options and MKV is by far the better option as it doesn't actually transcode the video. We package up the original frames into an MKV container, so it's faster and less resource intensive.

Unfortunately there's no option to add timestamps to MKV exports through the SDK.

You have me thinking about ways to leverage ffmpeg to do it though. I've added timestamps to video with it before, but I'll have to look into making a command to stream binary video out from MilestonePSTools into the stdin stream of ffmpeg.

https://stackoverflow.com/questions/12999674/ffmpeg-which-file-formats-support-stdin-usage#13000183

subbuun commented 9 months ago

Thanks @joshooaj

Can you please advise on the way to use "x265vfw - H.264/MPEG-4 AVC codec" for exporting the video in AVI format.

Tarterman commented 9 months ago

@subbuun, try running this to see exactly how the codec name is listed:

$exporter = [VideoOS.Platform.Data.AVIExporter]::new()
$exporter.CodecList

That will return all of the currently installed codecs. How they are listed there should be how you would want to list it with the Start-Export -Codec command. As an example, here is my output. It has the default Windows codecs plus the Xvid codec that I installed.

image

subbuun commented 9 months ago

Thanks @Tarterman I was able to get the list of Codec.

But I have found all the cameras with H.265 Compression are throwing the below error. I.e. unable to export using the PSTools. But able to export from Smart Client for the same camera and timestamp.

Start Export Error

joshooaj commented 9 months ago

Hi @subbuun,

Thank you - I just wanted to let you know that I reproduced this today. The MIP SDK's exporters seem to fail to export H265 for some reason and I'm not sure yet if it's something that MilestonePSTools is doing wrong or if it's a MIP SDK issue to be solved by our MIP product team. I'll find out and report back!

Cheers,

Josh

joshooaj commented 6 months ago

Hi @subbuun,

I thought I had reproduced the issue but the SDK development team couldn't reproduce it, and I haven't been able to reproduce it since. I've had no issues exporting H.265 video with MilestonePSTools from...

If you (or anyone else) is still unable to export H.265 video, we need to know the Milestone XProtect version, the MilestonePSTools version, the commands used to prepare and start the export, and if possible, an MKV export from Smart Client would be useful as well. If Smart Client can't export it then there's no question that a case should be opened with our technical support team.

The Start-Export cmdlet has some very poorly designed parameters / parametersets making it unclear which parameters are required for different export types. For what it's worth, when you use the MKV format, the Codec parameter is not relevant because an MKV export doesn't change the codec under any circumstances. The codec parameter is only relevant when Format is "AVI". Same with MaxAviSizeInBytes.

My best guess, based on the error message, is that I only reproduced it by accident by using a bad StartTime and EndTime. These parameters expect DateTime values, so when you pass in a string like '2023-11-09 14:00:00', PowerShell will try to parse it as a DateTime object.

On my system (and probably most others), it parses as I would expect, to 2PM on November 9th. However, .NET doesn't know whether that DateTime is based on local time or UTC. Before we start the export, we call "ToUniversalTime()" to ensure the UTC time is used when requesting media from the recording server. If the timestamps you passed in at the commandline were already in UTC, the actual time for the export would have been offset by whatever your timezone offset is. I'm not saying that is what happened in your case, but it's a common mistake when working with .NET DateTime objects. Jon Skeet made NodaTime specifically because of how hard "time" is for developers and how limited the DateTime class is.

To see if the timestamp string you use ends up being parsed as you would expect, you can try this. The result should be whatever the UTC time is for "14:00:00" in your machine's configured timezone.

$timestamp = [datetime]'2023-11-09 14:00:00'
$timestamp.ToUniversalTime()

I'm going to close this issue but if you or anyone else using MilestonePSTools has the issue again, please open a new issue with as much information about your environment as possible. In most cases, an inability to export in MKV is going to be an issue with our MIP SDK and not necessarily MilestonePSTools itself, but we can help you identify if that is the case.

joshooaj commented 3 months ago

Hi @subbuun,

I discovered this week that software decoding of H.265 video has basically always been broken in MilestonePSTools. The intermittent ability to reproduce the issue seems to come down to whether or not Intel or Nvidia hardware acceleration is available. If software decoding is required, we use an Intel MediaSDK plugin loaded from a DLL in a subdirectory of the executing application. This is fine for Smart Client or other standalone executables, but for MilestonePSTools the executing application is powershell.exe running from the C:\Windows\System32\... path.

Here's a link to a more detailed description and temporary solution: https://github.com/MilestoneSystemsInc/PowerShellSamples/issues/126#issuecomment-2125959775