1、add video stream demo

2、add config read string function
This commit is contained in:
wangjian 2022-10-23 13:33:16 +08:00
parent 6717831eb6
commit 37f7ba99ea
2 changed files with 44 additions and 23 deletions

View File

@ -7,13 +7,12 @@ import (
"fmt"
"git.hpds.cc/Component/network/log"
"git.hpds.cc/pavement/hpds_node"
"github.com/disintegration/imaging"
ffmpeg "github.com/u2takey/ffmpeg-go"
"io"
"os"
"strconv"
"time"
"github.com/disintegration/imaging"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
func main() {
@ -37,7 +36,7 @@ func main() {
if len(img) > 0 {
//log.Printf("send img %s", HexToString(img))
str := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
tick := time.Now().Format("20060102150405") + str[10:]
tick := fmt.Sprintf("%d_%s", id, time.Now().Format("20060102150405")+str[10:])
go WriteFile(fmt.Sprintf("./%s.jpeg", tick), img)
n, err := ap.Write(img)
if err != nil {
@ -50,24 +49,45 @@ func main() {
}
video := VideoImage{}
ffStream := ffmpeg.Input("rtmp://ns8.indexforce.com/home/mystream")
//i := 0
//quit := make(chan int)
tick := time.NewTicker(time.Millisecond * 42)
defer tick.Stop()
go func() {
i := 0
quit := make(chan int)
//tick := time.Tick(time.Second)
select {
case <-quit:
fmt.Println("quit")
return
case <-time.After(time.Millisecond * 42):
for range tick.C {
if i%24 == 0 {
img, err := video.ExtractImageBytes(ffStream, 1)
img, err := video.ExtractImageBytes(ffStream, i)
if err != nil {
fmt.Printf("ExtractImage64 error: %v\n", err)
}
fmt.Printf("i ========== %d \n", i)
send(i, img)
//log.Debugf("send img %#v", img)
}
i++
}
}()
select {}
//ch := make(chan int, 1)
//
//select {
//case <-quit:
// fmt.Println("quit")
// close(ch)
// return
//case <-tick.C:
// if i%24 == 0 {
// img, err := video.ExtractImageBytes(ffStream, i)
// if err != nil {
// fmt.Printf("ExtractImage64 error: %v\n", err)
// }
// fmt.Printf("i ========== %d \n", i)
// send(i, img)
// //log.Debugf("send img %#v", img)
// }
// i++
//}
}
func genSha1(buf []byte) string {

View File

@ -19,7 +19,7 @@ var (
func main() {
sf := hpds_node.NewStreamFunction(
"echo-sf",
hpds_node.WithMqAddr("localhost:27188"),
hpds_node.WithMqAddr("localhost:27187"),
hpds_node.WithObserveDataTags(ImageDataKey),
hpds_node.WithCredential("token:z1"),
)
@ -52,13 +52,14 @@ func Handler(img []byte) (byte, []byte) {
//} else {
// fmt.Println("GO: Run bindgen -- infer FAILED")
//}
id := atomic.AddUint64(&counter, 1)
str := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
tick := time.Now().Format("20060102150405") + str[10:]
go WriteFile(fmt.Sprintf("./%s.jpeg", tick), img)
go WriteFile(fmt.Sprintf("./%d_%s.jpeg", id, tick), img)
// print logs
hash := genSha1(img)
log.Printf("received image-%d hash %v, img_size=%d \n", atomic.AddUint64(&counter, 1), hash, len(img))
log.Printf("received image-%d hash %v, img_size=%d \n", id, hash, len(img))
return 0x11, nil
}