Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek time and Change Playback speed [PLAY functions] #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions format/rtspv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,39 @@ func ReplayDial(options RTSPClientOptions, startTime string) (*RTSPClient, error
return client, nil
}

func (client *RTSPClient) SeekTime(startTime string, scale float64, endTime string) error {
// Prepare new PLAY request headers
scaleStr := fmt.Sprintf("%.6f", scale)
headers := map[string]string{
"Require": "onvif-replay",
"Scale": scaleStr,
"Range": "clock=" + startTime + "-" + endTime}
// Send the PLAY request with the new scale
err := client.request(PLAY, headers, client.control, false, true)
if err != nil {
client.Println("Failed to Change SEEKTIME", err)
return fmt.Errorf("failed to change speed: %w", err)
}
return nil
}

func (client *RTSPClient) ChangeSpeed(scale float64) error {
// Convert scale to string format
scaleStr := fmt.Sprintf("%.6f", scale)
// Prepare new PLAY request headers
headers := map[string]string{
"Require": "onvif-replay",
"Scale": scaleStr,
"Speed": "1.000000"}
// Send the PLAY request with the new scale
err := client.request(PLAY, headers, client.control, false, true)
if err != nil {
return fmt.Errorf("failed to change speed: %w", err)
}
client.Println("Speed changed to scale:", scale)
return nil
}

func (client *RTSPClient) ControlTrack(track string) string {
if strings.Contains(track, "rtsp://") {
return track
Expand Down
Loading