M
M
Maxim_SH2016-01-20 10:12:08
go
Maxim_SH, 2016-01-20 10:12:08

How to convert rstp streams of ip cameras to images in golang in parallel?

Hello!
The following situation is the n-th number of ip cameras from which it is necessary to convert the rtsp stream into an image and it is desirable to do this in parallel.
Made a test case with 3 cameras, looks like this:

func convert1() {
  cmd := "/usr/bin/ffmpeg"
  args := []string{"-i", "rtsp://ip:port", "-f", "image2", "filename.ext"}

  exec.Command(cmd, args...).Run()
}

func convert2() {
  cmd := "/usr/bin/ffmpeg"
  args := []string{"-i", "rtsp://ip:port", "-f", "image2", "filename.ext"}

  exec.Command(cmd, args...).Run()
}

func convert3() {
  cmd := "/usr/bin/ffmpeg"
  args := []string{"-i", "rtsp://ip:port", "-f", "image2", "filename.ext"}

  exec.Command(cmd, args...).Run()
}

func main() {
  go convert1()
  go convert2()
  convert3()
  fmt.Println("RTSP streams of videocameras successfully converted!")
}

In this case, everything works fine. But how can I implement something like this, if I get information about cameras in json and the number of cameras can be different all the time. As an option, we can convert json into a map, where the keys are the names of the images, and the values ​​are links to rtsp camera streams, or vice versa. Then it goes through this map and converts based on the data contained in the map. Then how to implement parallel conversion, similar to the above example? I ask for help in resolving this issue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2016-01-20
@Maxim_SH

Make one conversion function that would take parameters: ip, port, output file.
In a loop, run this function with the desired parameters through go
To wait for the completion of goroutines, you can use sync.WaitGroup
nathanleclaire.com/blog/2014/02/15/how-to-wait-for...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question