Skip to content

Commit

Permalink
refactor(config): Refactor RSTP config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tphakala committed Mar 17, 2024
1 parent b3e6f2e commit 94b19e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/realtime/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func setupFlags(cmd *cobra.Command, settings *conf.Settings) error {
cmd.Flags().StringVar(&settings.Realtime.AudioExport.Path, "clippath", viper.GetString("realtime.audioexport.path"), "Path to save audio clips")
cmd.Flags().StringVar(&settings.Realtime.Log.Path, "logpath", viper.GetString("realtime.log.path"), "Path to save log files")
cmd.Flags().BoolVar(&settings.Realtime.ProcessingTime, "processingtime", viper.GetBool("realtime.processingtime"), "Report processing time for each detection")
cmd.Flags().StringVar(&settings.Realtime.RTSP, "rtsp", viper.GetString("realtime.rtsp"), "URL of RTSP audio stream to capture")
cmd.Flags().StringVar(&settings.Realtime.RTSPTransport, "rtsptransport", viper.GetString("realtime.rtsptransport"), "RTSP transport (tcp/udp)")
cmd.Flags().StringVar(&settings.Realtime.RTSP.Url, "rtsp", viper.GetString("realtime.rtsp.url"), "URL of RTSP audio stream to capture")
cmd.Flags().StringVar(&settings.Realtime.RTSP.Transport, "rtsptransport", viper.GetString("realtime.rtsp.transport"), "RTSP transport (tcp/udp)")

// Bind flags to the viper settings
if err := viper.BindPFlags(cmd.Flags()); err != nil {
Expand Down
14 changes: 11 additions & 3 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ type Settings struct {
Enabled bool // true to enable dog bark filter
}

RTSP string // RTSP stream URL
RTSPTransport string //RTSP Transport Protocol
RTSP struct {
Url string // RTSP stream URL
Transport string // RTSP Transport Protocol
}
}

WebServer struct {
Expand Down Expand Up @@ -215,11 +217,13 @@ birdnet:
realtime:
interval: 15 # duplicate prediction interval in seconds
processingtime: false # true to report processing time for each prediction
audioexport:
enabled: true # true to export audio clips containing indentified bird calls
path: clips/ # path to audio clip export directory
type: wav # only wav supported for now
log:
log:
enabled: false # true to enable OBS chat log
path: birdnet.txt # path to OBS chat log
Expand All @@ -228,6 +232,10 @@ realtime:
debug: false # true to enable birdweather api debug mode
id: 00000 # birdweather ID
rtsp:
url: # RTSP stream URL
transport: tcp # RTSP Transport Protocol
privacyfilter:
enabled: true
Expand Down
12 changes: 6 additions & 6 deletions internal/myaudio/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func CaptureAudio(settings *conf.Settings, wg *sync.WaitGroup, quitChan chan struct{}, restartChan chan struct{}, audioBuffer *AudioBuffer) {
if settings.Realtime.RTSP != "" {
if settings.Realtime.RTSP.Url != "" {
// RTSP audio capture
captureAudioRTSP(settings, wg, quitChan, restartChan, audioBuffer)
} else {
Expand Down Expand Up @@ -172,15 +172,15 @@ func captureAudioRTSP(settings *conf.Settings, wg *sync.WaitGroup, quitChan chan
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

rtsp_transport := "udp"
if (settings.Realtime.RTSPTransport != "") {
rtsp_transport = settings.Realtime.RTSPTransport;
rtspTransport := "udp"
if settings.Realtime.RTSP.Transport != "" {
rtspTransport = settings.Realtime.RTSP.Transport
}

// Start ffmpeg
cmd := exec.CommandContext(ctx, "ffmpeg",
"-rtsp_transport", rtsp_transport, // RTSP transport protocol (tcp/udp)
"-i", settings.Realtime.RTSP,
"-rtsp_transport", rtspTransport, // RTSP transport protocol (tcp/udp)
"-i", settings.Realtime.RTSP.Url, // RTSP url
"-loglevel", "error",
"-vn", // No video
"-f", "s16le", // 16-bit signed little-endian PCM
Expand Down

0 comments on commit 94b19e7

Please sign in to comment.