Skip to content

Commit

Permalink
Merge pull request #14 from wehbs/pushover-support
Browse files Browse the repository at this point in the history
Pushover support
  • Loading branch information
chiefMarlin authored Sep 15, 2023
2 parents c79bbbc + f10dcc7 commit 294d181
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ rec
pkg/objectPredict/lib.tgz
pkg/objectPredict/lib/
firescrew
config.json
demoStream/demoConfig.json
.aider*
.DS_Store
demoStream/rtspServer/rtspServer
demoStream/sample.mp4
69 changes: 69 additions & 0 deletions firescrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
"fmt"
"image"
"image/color"
"image/color/palette"
"image/draw"
"image/gif"
"image/jpeg"
"image/png"
"io"
Expand Down Expand Up @@ -1733,6 +1735,16 @@ func endMotionEvent() {
// Log("info", fmt.Sprintf("SINCE_LAST_EVENT: %d GAP: %d", time.Since(runtimeConfig.MotionTriggeredLast), time.Duration(globalConfig.Motion.EventGap)*time.Second))
Log("info", "MOTION_ENDED")
runtimeConfig.MotionMutex.Lock()

// Create gif from snapshots
fullPath, err := createGifFromSnapshots(runtimeConfig.MotionVideo.Snapshots)
if err != nil {
// Handle error
fmt.Println("An error occurred:", err)
} else {
fmt.Println("GIF created at:", fullPath)
}

// Stop Hi res recording and dump json file as well as clear struct
runtimeConfig.MotionVideo.MotionEnd = time.Now()
runtimeConfig.HiResControlChannel <- RecordMsg{Record: false}
Expand Down Expand Up @@ -1807,3 +1819,60 @@ func endMotionEvent() {
runtimeConfig.MotionTriggered = false
runtimeConfig.MotionMutex.Unlock()
}

func createGifFromSnapshots(snapshots []string) (string, error) {
// Check if snapshots slice is empty
if len(snapshots) == 0 {
return "", errors.New("no snapshots available for creating gif")
}

// Create a new array to hold the modified snapshot paths
newSnapshots := make([]string, len(snapshots))
for i, snapshot := range snapshots {
newSnapshots[i] = filepath.Join(globalConfig.Video.HiResPath, snapshot)
}

var frames []*image.Paletted
var delays []int

// Use newSnapshots instead of the original snapshots array
for _, snapshot := range newSnapshots {
imgFile, err := os.Open(snapshot)
if err != nil {
return "", err
}
defer imgFile.Close()

img, err := jpeg.Decode(imgFile)
if err != nil {
return "", err
}

bounds := img.Bounds()
paletted := image.NewPaletted(bounds, palette.Plan9)
draw.Draw(paletted, bounds, img, bounds.Min, draw.Over)
frames = append(frames, paletted)

delays = append(delays, 40)
}

// Create GIF filename
outputFilename := fmt.Sprintf("gif_%s.gif", runtimeConfig.MotionVideo.ID)
fullPath := filepath.Join(globalConfig.Video.HiResPath, outputFilename)

outFile, err := os.Create(fullPath)
if err != nil {
return "", err
}
defer outFile.Close()

err = gif.EncodeAll(outFile, &gif.GIF{
Image: frames,
Delay: delays,
})
if err != nil {
return "", err
}

return fullPath, nil
}

0 comments on commit 294d181

Please sign in to comment.