Create GIFs from alerts & clips; Send Pushover notifications with GIF attachments

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)
 
  • Like
Reactions: jaydeel
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.
 
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:
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:
  • Like
Reactions: EvanVanVan
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.
 
  • Love
Reactions: LazySecurity247
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:
  • Like
Reactions: jaydeel
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:
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:
  • Like
Reactions: jaydeel
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
 
  • Like
Reactions: silencery
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 and TotalMs to the script's performance log (see screenshot #2)

Screenshot #1 - shows improved usage guide
V2.0_usage_guide.png

Screenshot #2 - shows the new columns in the the script's performance csv file
V2.0_perf_csv_log.png
 
Last edited:
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:
  • Like
Reactions: jrbeddow
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:
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!
 
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:
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.
 
Script updated to V2.1. see post #1 to download the zip file.

Key features of this new version are:
  • BREAKING CHANGE: must replace old user-settings file
  • NEW: script now supports Telegram Bot notifications (alternative to Pushover);
  • NEW: added argument -PushService ('Pushover' or 'Telegram') to support on-demand service selection (case-insensitive)
  • NEW: added argument -Sound ('Pushover' only) to support on-demand service selection
  • NEW: script can now make GIFs via BI Clipboard clips (or Alerts created via Clipboard clips)
  • FIXED: script now handles DAT files with JPG images stored oldest to newest; effective BI 5.9.4.11+
  • IMPROVED: DAT extraction more efficient (gets BI version from registry instead of JSON call)
  • IMPROVED: -Live argument now supports the use of non-default folder naming patterns in Camera settings > Record > Video
Why you might want to use this update:
  1. This update solves the problem with GIFs playing in reverse after 5.9.4.11... as first described in this post.
  2. This update is a bit in faster in creating GIFs from DAT files. And the total script time for Pushover messages is ~5 seconds. See the performance charts below.

Performance results...
I'm routinely seeing GIF make times of ~4 sec for DAT files containing 10-13 JPG images.
This chart also shows Pushover notification process times.
V2.1_chart_viaDat_pushover.png


Telegram notifications appear to be 1+ second slower than Pushover notifications (while this is a smaller data set than the chart above, I've observed this in other testing as well).
V2.1_chart_viaDat_telegram.png


Updated usage guide...
V2.1_usage_guide.png
 
Last edited:
  • Like
Reactions: looney2ns
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
First time user of this PS tool and want to say great work Jaydeel, I'm looking forward to getting GIF alerts. (With the recent Android alerting inconsistencies I'm looking to move over to Pushover.)

General setup and configuration was a breeze, however I hit a snag with getting the images from BVR files. (No img files would get created locally by the PS script.) I referenced LazySecurity247's post above because that was the only thing that worked for me.

Since we provide BI user credentials in the config file, could we use those to authenticate for the BVR image retrieval?

Thanks.
 
Script updated to V2.2. see post #1 to download the zip file.

Key features of this new version are:
  • BREAKING CHANGE: must replace old user-settings file
  • ADDED: new argument -Examples to provide the user with easy-to-try example commands
  • ADDED: new argument -Devices to support custom device(s) for notifications (Pushover only); comma-delimited
  • ADDED: new column 'ScriptHost' to script's CSV log file
  • ADDED: user setting '$append_performance_tag_details_flg' to hide default performance details notification tag
  • ADDED: user setting '$jpg_images_from_substream_flg' to enable extracting JPGs from the BVR default-stream
  • ADDED: user setting '$jpg_images_match_gif_height_flg' to enable extracting full-sized JPGs from BVR files
  • CHANGED: script can now use BI credentials to create GIFs using JPG files extracted from BVR files
  • CHANGED: removed user-setting $bi_alerts_folder_path; script now retrieves the setting from the Windows registry
  • CHANGED: removed user-setting $bi_webserver; script now retrieves the setting from the Windows registry
  • CHANGED: removed user-setting $dat_image_interval_msec; script now retrieves the setting from the Windows registry
  • CHANGED: script now validates user-setting $bi_new_folder_paths against folders in the BI settings Storage tab
It may worth reiterating that this script no longer requires DAT files to create GIFs.

Why you might want to use this update:
  1. You want to avoid using using an entry like ^192.168.1.* in Blue Iris Settings > 'Web server' > Advanced > 'Limit access by IP address'.
  2. You want to customize each camera's 'On alert' actions to have different Pushover device lists (and/or sounds and priorities).
  3. You want to see performance info (GifMakeMsec) in the notification message.
  4. You want to experiment with extracting JPGs from the BVR main stream, or extracting larger JPGs from the BVR.
Updated usage guide:
V2.2_usage_guide.png

NEW examples guide:
V2.2_examples_guide.png

New columns in the the script's performance csv file (since V2.0)
V2.2_perf_csv_log.png
 
Last edited:
  • Like
Reactions: jrbeddow