Live video on the AT Protocol
at eli/embedded-rtmp-server 45 lines 1.1 kB view raw
1package cmd 2 3import ( 4 "fmt" 5 "io" 6 "net/http" 7 "os" 8) 9 10func Live(streamKey string, httpInternalAddr string) error { 11 // Create the URL for the live stream endpoint 12 url := fmt.Sprintf("http://%s/live/%s", httpInternalAddr, streamKey) 13 14 // Create a new HTTP request with POST method 15 req, err := http.NewRequest("POST", url, os.Stdin) 16 if err != nil { 17 return fmt.Errorf("error creating request: %w", err) 18 } 19 20 // Set appropriate headers if needed 21 req.Header.Set("Content-Type", "video/x-matroska") // Assuming MKV format, adjust if needed 22 23 // Create HTTP client and send the request 24 client := &http.Client{} 25 resp, err := client.Do(req) 26 if err != nil { 27 return fmt.Errorf("error sending stream: %w", err) 28 } 29 defer resp.Body.Close() 30 31 // Check response status 32 if resp.StatusCode != http.StatusOK { 33 body, _ := io.ReadAll(resp.Body) 34 return fmt.Errorf("server returned non-OK status: %d %s - %s", 35 resp.StatusCode, resp.Status, string(body)) 36 } 37 38 // Copy response to stdout (if any) 39 _, err = io.Copy(os.Stdout, resp.Body) 40 if err != nil { 41 return fmt.Errorf("error reading response: %w", err) 42 } 43 44 return nil 45}