Add SampleRate and Channels fields to IPCamera configuration and update audio stream handling

This commit is contained in:
Cédric Verstraeten
2025-06-16 06:37:19 +00:00
parent 620117c31b
commit 120054d3e5
5 changed files with 19 additions and 1 deletions
+2
View File
@@ -342,6 +342,8 @@ func (g *Golibrtsp) Connect(ctx context.Context) (err error) {
IsVideo: false,
IsAudio: true,
IsBackChannel: false,
SampleRate: audioFormaMPEG4.Config.SampleRate,
Channels: audioFormaMPEG4.Config.ChannelCount,
})
// Set the index for the audio
+2
View File
@@ -85,6 +85,8 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat
videoStreams, _ := rtspClient.GetVideoStreams()
if len(audioStreams) > 0 {
audioCodec = audioStreams[0].Name
config.Capture.IPCamera.SampleRate = audioStreams[0].SampleRate
config.Capture.IPCamera.Channels = audioStreams[0].Channels
}
if len(videoStreams) > 0 {
videoCodec = videoStreams[0].Name
+2
View File
@@ -92,6 +92,8 @@ type IPCamera struct {
SPSNALUs [][]byte `json:"sps_nalus,omitempty" bson:"sps_nalus,omitempty"`
PPSNALUs [][]byte `json:"pps_nalus,omitempty" bson:"pps_nalus,omitempty"`
VPSNALUs [][]byte `json:"pps_nalus,omitempty" bson:"pps_nalus,omitempty"`
SampleRate int `json:"sample_rate,omitempty" bson:"sample_rate,omitempty"`
Channels int `json:"channels,omitempty" bson:"channels,omitempty"`
}
// USBCamera configuration, such as the device path (/dev/video*)
+6
View File
@@ -42,4 +42,10 @@ type Stream struct {
// IsBackChannel is true if this stream is a back channel.
IsBackChannel bool
// SampleRate is the sample rate of the audio stream.
SampleRate int
// Channels is the number of audio channels.
Channels int
}
+7 -1
View File
@@ -355,8 +355,14 @@ func (mp4 *MP4) Close(config *models.Config) {
if mp4.AudioTrackName == "AAC" || mp4.AudioTrackName == "MP4A" {
// Add an audio track to the moov box
init.AddEmptyTrack(audioTimescale, "audio", "und")
// Check if the same sample rate is set, otherwise we default to 48000
audioSampleRate := 48000
if config.Capture.IPCamera.SampleRate > 0 {
audioSampleRate = config.Capture.IPCamera.SampleRate
}
// Set the audio descriptor
err := init.Moov.Traks[1].SetAACDescriptor(29, 48000)
err := init.Moov.Traks[1].SetAACDescriptor(29, audioSampleRate)
if err != nil {
//panic(err)
}