Create GIFs from alerts & clips; Send Pushover notifications with GIF attachments [Part 1/3]

silencery

Pulling my weight
Joined
Oct 6, 2015
Messages
230
Reaction score
158
It may be a bug... checking now.

EDIT: Confirmed bug. I mistyped the -Priority parameter as [string] instead of [int]. PS7 was forgiving, but PS5 was not.
When Powershell is executed in the background (e.g., from a Blue Iris Run-a-program action), scripts are executed using PS5.
When I test scripts from the Console, I'm usually using PS7. I forgot to test also in Powershell-ISE, which uses PS5.
Makes perfect sense. I should have caught that myself; I appreciate your help!!

New update works a treat. Awesome work!

If time permits, my plan is to write an add-on script or maybe fork yours to work with Home Assistant. My hope is to eventually have more granular control over notifications tied into home automation (i.e. quiet hours, notification debouncer, priority handling when alarm is set, etc)
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
New in Blue Iris version 5.7.9.0 (link),
Ken has added a new feature to the Clips list that makes it much easier to get any clip's or alert's database record ID,
Just right-click while holding down the Ctrl key over an alert in the Clips list
. This copies the item's database record to the clipboard.

An example of how this might be might be handy if you ever want to create/send an on-demand GIF file using the script in post #1.
  1. Ctrl-Right click on the Alert of interest in the Blue Iris Clips list (hit the Esc key to close the context menu).
  2. Type the following command in the Powershell.exe or Powershell-ISE console BI_gif_tool.ps1 -AlertRec ""
  3. Use the back arrow to move the cursor between the quotes
  4. Type Ctrl-V to paste the db record id into the command ... yielding something like BI_gif_tool.ps1 -AlertRec "@173695285"
  5. Hit the enter key to execute the script.
This new feature is an improvement over the previous recommendation:
  1. Open UI3,
  2. Locate the Alert of interest, then play it,
  3. Grab the alert's database record id from the browser's address bar, and
  4. Paste the database record id in the following command BI_gif_tool.ps1 -UI3Rec xxxxxx.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
Script updated to V1.9. see post #1.

Changelog:
  1. FIXED BUG: SendPushover() call lacked grave accent (`) after -Camera param line; caused malformed value
  2. FIXED BUG: all DAT-extracted JPG files lacked JPEG Interchange Format end-of-image byte marker ('FF D9')
  3. IMPROVED: JPG validation function 'IsJpegFileValid()' - now also tests for valid end-of-image byte marker
  4. ADDED: a repair is now attempted for situations where the JPG start- & end-of-image byte markers appear to be unbalanced
  5. CHANGED: The -Help argument (usage guide) no longer displayed by default
  6. DISABLED: argument -NukeDatFile has been disabled until Blue Iris provides a safe method to delete DAT files
 
Last edited:
Joined
Oct 20, 2023
Messages
1
Reaction score
1
Location
Israel
first of all, Thank You! amazing work.

in order to make it work with jpeg from bvr, I needed to add the ip of the machine running the script to the setting -> web server -> advanced
with ^ prefix so no password is required (at least on my computer it didn't work until added)
example:
^192.168.1.50
1697809183535.png


But my issue is with DAT extract, my export location for bvr & alerts is with some sub folders to make it easier for windows to browse...
the extract works but the create gif command is searching in another folder (without the sub folders) for the jpgs...

my Video "special" path is : (D:\Blueiris\New) + %Y-%m-%d\&CAM\&CAM.%Y%m%d_%H%M%S (example: "D:\BlueIris\New\2023-10-20\Front\Front.20231020_160000.bvr")
my Alerts "special" path is : (D:\Blueiris\Alert) + %Y-%m-%d\&CAM\&CAM.%Y%m%d_%H%M%S (example: "D:\BlueIris\Alerts\2023-10-20\Front\Front.20231020_142356.289015.3-1.dat")
1697807517491.png


Regards.
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
first of all, Thank You! amazing work.

in order to make it work with jpeg from bvr, I needed to add the ip of the machine running the script to the setting -> web server -> advanced
with ^ prefix so no password is required (at least on my computer it didn't work until added)
example:
^192.168.1.50
View attachment 175519

But my issue is with DAT extract, my export location for bvr & alerts is with some sub folders to make it easier for windows to browse...
the extract works but the create gif command is searching in another folder (without the sub folders) for the jpgs...

my Video "special" path is : (D:\Blueiris\New) + %Y-%m-%d\&CAM\&CAM.%Y%m%d_%H%M%S (example: "D:\BlueIris\New\2023-10-20\Front\Front.20231020_160000.bvr")
my Alerts "special" path is : (D:\Blueiris\Alert) + %Y-%m-%d\&CAM\&CAM.%Y%m%d_%H%M%S (example: "D:\BlueIris\Alerts\2023-10-20\Front\Front.20231020_142356.289015.3-1.dat")
View attachment 175514

Regards.
Thanks.
I’ve had another similar request for my bi_clip_usage script.
I think I have a solution. It will be a few days. Stay tuned.
 

silencery

Pulling my weight
Joined
Oct 6, 2015
Messages
230
Reaction score
158
After using this for months with no problems (thanks again @jaydeel !) I've run into a weird edge case problem.
For various reasons, I had to reconfigure my blueiris server to use a network share for clip storage.

After moving to network share for storage, I noticed GIF files were no longer animated. The script was only able to generate still images. After investigating, it seems that the script run from BlueIris seems to have some sort of problem accessing dat files. To test, I ran the following command manually from powershell, and it worked perfectly. However, when I run the same command from BI, the script switches over to bvr file source.

Has anyone run into a similar problem? If so, any insights on possible solutions?

Thanks!

Command
Code:
"C:\BlueIris\custom-scripts\BI_gif_tool.ps1" -UI3Rec 997990779
BI_gif_tool.ps1.csv results
Code:
"Timestamp","SourceFile","GifMethod","GifImagesCnt","GifHeight","GifFPS","GifTrimBegPct","GifTrimEndPct","GifTrimCustPct","GifDurSec","GifSizeKb","GifMakeMs","GifJpgWxH","AlertRecId"
powershell results (GIF working): "2024/02/27_16:56:43","PorchDB-DS.20240227_150207.380056.3-1.dat","viaDat","5","320","2","0","40","40","5.1","220","2875.2","640x480",""
run in BI results (GIF not working): "2024/02/27_16:54:36","D:\BlueIris\New\PorchDB-DS.20240227_150207.bvr","viaClip","10","320","2","0","40","40","5.1","48","4225.1","x",""
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
After using this for months with no problems (thanks again @jaydeel !) I've run into a weird edge case problem.
For various reasons, I had to reconfigure my blueiris server to use a network share for clip storage.

After moving to network share for storage, I noticed GIF files were no longer animated. The script was only able to generate still images. After investigating, it seems that the script run from BlueIris seems to have some sort of problem accessing dat files. To test, I ran the following command manually from powershell, and it worked perfectly. However, when I run the same command from BI, the script switches over to bvr file source.

Has anyone run into a similar problem? If so, any insights on possible solutions?

Thanks!

Command
Code:
"C:\BlueIris\custom-scripts\BI_gif_tool.ps1" -UI3Rec 997990779
BI_gif_tool.ps1.csv results
Code:
"Timestamp","SourceFile","GifMethod","GifImagesCnt","GifHeight","GifFPS","GifTrimBegPct","GifTrimEndPct","GifTrimCustPct","GifDurSec","GifSizeKb","GifMakeMs","GifJpgWxH","AlertRecId"
powershell results (GIF working): "2024/02/27_16:56:43","PorchDB-DS.20240227_150207.380056.3-1.dat","viaDat","5","320","2","0","40","40","5.1","220","2875.2","640x480",""
run in BI results (GIF not working): "2024/02/27_16:54:36","D:\BlueIris\New\PorchDB-DS.20240227_150207.bvr","viaClip","10","320","2","0","40","40","5.1","48","4225.1","x",""
Please confirm that the user_settings file setting $bi_alert_folder_path has been updated to reflect the new location for the Alerts folder (if indeed it has changed).

The script will attempt to extract 10 images from the BVR file if the DAT file cannot be found. These images will span the duration of the alert.
 
Last edited:

silencery

Pulling my weight
Joined
Oct 6, 2015
Messages
230
Reaction score
158
Appreciate your reply jaydeel. Yes, confirmed that the pathing is correct for $bi_alert_folder_path.

EDIT: Actually, now that you mention it, I tried using the UNC path (/server/bi/alerts) instead of the locally mapped path (D:/bi/alerts) and it seems to be working. Thanks!!!
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
Appreciate your reply jaydeel. Yes, confirmed that the pathing is correct for $bi_alert_folder_path.

EDIT: Actually, now that you mention it, I tried using the UNC path (/server/bi/alerts) instead of the locally mapped path (D:/bi/alerts) and it seems to be working. Thanks!!!
Good catch. This is mentioned in the Help PDF in the 'Testing the Action Set' section of the 'Alerts and Actions' chapter.

Screenshot_20240228_050608_Dropbox.jpg
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
Script updated to V2. see post #1 to download the file

Key features of this new version are:
  • An improved usage guide (-Help argument, see screenshot #1).
  • Added argument -Latest to make GIF from a camera's most recent alert.
  • Eliminated the delay when using the -Live argument
  • Improved support for BVR-derived GIFs (for users that don't wish to create DAT files)
    • script now supports multiple Blue Iris 'New' folders
    • script now supports the use of non-default folder naming patterns in Camera settings > Record > Video (ADDED: 3/21/2024)
    • argument -TrimBegPct may be negative to include pre-trigger images in the GIF
  • Improved support for DAT-derived GIFs
    • added argument -DatImageMsec to improve GIF duration estimates
    • arguments -TrimBegPct & -TrimEndPct now ALSO work for these GIFs (by skipping the the extraction of an appropriate number of JPGs from the DAT file)
  • Added 2 columns ('PushoverMs' & 'TotalMs
    ') to the script's performance log (see screenshot #2)

Screenshot #1 - shows improved usage guide

V2_usage_guide.png

Screenshot #2 - shows the new columns in the the script's performance csv file

V2_perf_csv_log.png
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
V2 usage examples...

Make and send a 'Live' GIF from a camera

bi_gif_tool.ps1 -Camera "DW1" -Live -Seconds 5
Note: the default duration without the -Seconds argument is 10 seconds

Make and send a GIF from a DAT file (if it exists), or a BVR file (if the DAT file does not exist)
bi_gif_tool.ps1 -Camera "DW1" -Latest

Force a GIF to be derived from the BVR clip
bi_gif_tool.ps1 -Camera "DW1" -Latest -IgnoreDatFile

Add pre-trigger images to a BVR-derived GIF
bi_gif_tool.ps1 -Camera "DW1" -Latest -IgnoreDatFile -TrimBegPct -50
How this works... the script extracts images from the BVR file before the alert's offset. the number of images is calculated as a percentage of the duration of the GIF (10 seconds, by default).

Add pre-trigger images to a DAT-derived GIF
Edit the camera's settings... Camera settings > Alerts > AI configuration > '+ pre-tre-trigger images'
V2_dat_pretrigger_images.png

Trim 2 images from both ends of a DAT-derived GIF, where the DAT file contains 10 images
bi_gif_tool.ps1 -Camera "DW1" -Latest -TrimBegPct 20 -TrimEndPct 20
The resulting GIF should contain 6 images
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
V2 Blue Iris Alert Action Set examples

This is the 'Run a program' Action 'Parameters' string that I'm currently using for most of my cameras...
Code:
"C:\ps_scripts\BI_gif_tool.ps1" -Camera '&CAM' -Latest -Msg """<b>&CAM</b> &MEMO <a href='&WAN/alerts/&ALERT_DB?fulljpeg'>Hi-Res</a> <a href='&WAN/ui3.htm?rec=&ALERT_DB'>UI3</a>""" -Priority 2 -FPS 2 -Height 320
1710864845622.png


This is the 'Run a program' Action 'Parameters' string that I'm currently using for my driveway cameras... It adds the -AlertMemo argument for custom trimming based on AI labels.
Code:
"C:\ps_scripts\BI_gif_tool.ps1" -Camera '&CAM' -Latest -AlertMemo '&MEMO' -Msg """<b>&CAM</b> &MEMO <a href='&WAN/alerts/&ALERT_DB?fulljpeg'>Hi-Res</a> <a href='&WAN/ui3.htm?rec=&ALERT_DB'>UI3</a>""" -Priority 2 -FPS 2 -Height 320
For example:
1710864963197.png
 
Last edited:

fbest

n3wb
Joined
Jul 10, 2024
Messages
1
Reaction score
0
Location
UAE
Hi @jaydeel,

Thank you for sharing your impressive script!

I'm currently using a Telegram bot to send alerts as photos with a simple command. I'm interested in expanding its capabilities to include GIFs and MP4s, and I was looking at your script for guidance. However, at over 6k lines, it’s quite extensive and I'm not really that strong in PowerShell.

Could you help summarize the key points for extracting images? From a quick glance, I see that you're making requests to the BI web server and mentioned that you extract images using either BVR or DAT files. I'm already familiar with using FFmpeg for creating GIFs, so I don’t need help with that part.

I'm mainly interested in the technical details of extracting the images for GIF creation or exporting the alerts as MP4. Do you think exporting the alert as an MP4 might be more efficient?

Thanks in advance!

Cheers!
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
Hi @jaydeel,

Thank you for sharing your impressive script!

I'm currently using a Telegram bot to send alerts as photos with a simple command. I'm interested in expanding its capabilities to include GIFs and MP4s, and I was looking at your script for guidance. However, at over 6k lines, it’s quite extensive and I'm not really that strong in PowerShell.

Could you help summarize the key points for extracting images? From a quick glance, I see that you're making requests to the BI web server and mentioned that you extract images using either BVR or DAT files. I'm already familiar with using FFmpeg for creating GIFs, so I don’t need help with that part.

I'm mainly interested in the technical details of extracting the images for GIF creation or exporting the alerts as MP4. Do you think exporting the alert as an MP4 might be more efficient?

Thanks in advance!

Cheers!
It would be MUCH more efficient to write a function that works with the Telegram API, and use it instead of the current SendPushover() function. I'd be happy to try to create it, if that would work.

If you are instead wanting to recreate the script in another language, then all I can suggest is reading my code. It is well-commented. The key steps are these:
  1. get key properties for the alert (like the alert's clip offset and duration) from the Blue Iris database using the Blue Iris JSON interface alertlist and clipisitats commands
  2. extract JPGs from the binary DAT file (see function ExtractDatImages())
  3. or asynchronously extract JPGs from the alert's parent BVR file using multiple Blue Iris HTTP interface commands, like this
    $url = $bi_webserver_address + "/file/clips/" + $al_db_path + "?time=" + $time + "&cache=1&h=" + $Height
At first blush, I am doubtful that sending MP4 files is an option. The Pushover API has a modest size limit for attachments of (2.5MB). I've not looked at the Telegram API in a long time.
 
Last edited:

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,234
Reaction score
1,293
Location
SF Bay Area
I've just updated the script to send Telegram Bot GIF notifications (as an alternative to Pushover).

I could use a few beta testers. If you are game, please send me a DM.
 
Top