用go语言调用 shell 命令,每隔10s录一段10分钟的视频,并以时间命名视频文件名。代码如下:
package main
import (
"fmt"
"os/ exec "
"strings"
"time"
)
func main() {
for {
time.Sleep(time.Second * 10)
str := time.Now().Format("2006-01-02 15:04:05")
str = strings.Replace(str, "-", "", -1)
str = strings.Replace(str, ":", "", -1)
str = strings.Replace(str, " ", "", -1)
cmd := exec.Command("/bin/bash", "-c", "raspivid -o "+str+".h264 -t 600000")
err := cmd.Run()
if err != nil {
fmt.Println(err)
}
}
}
每隔10秒拍摄一张照片
package main
import (
"fmt"
"os/exec"
"strings"
"time"
)
func main() {
for {
time.Sleep(time.Second * 10)
str := time.Now().Format("2006-01-02 15:04:05")
str = strings.Replace(str, "-", "", -1)
str = strings.Replace(str, ":", "", -1)
str = strings.Replace(str, " ", "", -1)
cmd := exec.Command("/bin/bash", "-c", "raspistill -o "+str+".h264 -t 1")
err := cmd.Run()
if err != nil {
fmt.Println(err)
}
}
}