1、add video stream demo
2、add config read string function
This commit is contained in:
		
							parent
							
								
									6717831eb6
								
							
						
					
					
						commit
						37f7ba99ea
					
				|  | @ -7,13 +7,12 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"git.hpds.cc/Component/network/log" | 	"git.hpds.cc/Component/network/log" | ||||||
| 	"git.hpds.cc/pavement/hpds_node" | 	"git.hpds.cc/pavement/hpds_node" | ||||||
|  | 	"github.com/disintegration/imaging" | ||||||
|  | 	ffmpeg "github.com/u2takey/ffmpeg-go" | ||||||
| 	"io" | 	"io" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"time" | 	"time" | ||||||
| 
 |  | ||||||
| 	"github.com/disintegration/imaging" |  | ||||||
| 	ffmpeg "github.com/u2takey/ffmpeg-go" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func main() { | func main() { | ||||||
|  | @ -37,7 +36,7 @@ func main() { | ||||||
| 		if len(img) > 0 { | 		if len(img) > 0 { | ||||||
| 			//log.Printf("send img %s", HexToString(img))
 | 			//log.Printf("send img %s", HexToString(img))
 | ||||||
| 			str := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) | 			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) | 			go WriteFile(fmt.Sprintf("./%s.jpeg", tick), img) | ||||||
| 			n, err := ap.Write(img) | 			n, err := ap.Write(img) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
|  | @ -50,24 +49,45 @@ func main() { | ||||||
| 	} | 	} | ||||||
| 	video := VideoImage{} | 	video := VideoImage{} | ||||||
| 	ffStream := ffmpeg.Input("rtmp://ns8.indexforce.com/home/mystream") | 	ffStream := ffmpeg.Input("rtmp://ns8.indexforce.com/home/mystream") | ||||||
| 	i := 0 | 	//i := 0
 | ||||||
| 	quit := make(chan int) | 	//quit := make(chan int)
 | ||||||
| 	//tick := time.Tick(time.Second)
 | 	tick := time.NewTicker(time.Millisecond * 42) | ||||||
| 	select { | 	defer tick.Stop() | ||||||
| 	case <-quit: | 	go func() { | ||||||
| 		fmt.Println("quit") | 		i := 0 | ||||||
| 		return | 		for range tick.C { | ||||||
| 	case <-time.After(time.Millisecond * 42): | 			if i%24 == 0 { | ||||||
| 		if i%24 == 0 { | 				img, err := video.ExtractImageBytes(ffStream, i) | ||||||
| 			img, err := video.ExtractImageBytes(ffStream, 1) | 				if err != nil { | ||||||
| 			if err != nil { | 					fmt.Printf("ExtractImage64 error: %v\n", err) | ||||||
| 				fmt.Printf("ExtractImage64 error: %v\n", err) | 				} | ||||||
|  | 				fmt.Printf("i ========== %d \n", i) | ||||||
|  | 				send(i, img) | ||||||
|  | 				//log.Debugf("send img %#v", img)
 | ||||||
| 			} | 			} | ||||||
| 			send(i, img) | 			i++ | ||||||
| 			//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 { | func genSha1(buf []byte) string { | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ var ( | ||||||
| func main() { | func main() { | ||||||
| 	sf := hpds_node.NewStreamFunction( | 	sf := hpds_node.NewStreamFunction( | ||||||
| 		"echo-sf", | 		"echo-sf", | ||||||
| 		hpds_node.WithMqAddr("localhost:27188"), | 		hpds_node.WithMqAddr("localhost:27187"), | ||||||
| 		hpds_node.WithObserveDataTags(ImageDataKey), | 		hpds_node.WithObserveDataTags(ImageDataKey), | ||||||
| 		hpds_node.WithCredential("token:z1"), | 		hpds_node.WithCredential("token:z1"), | ||||||
| 	) | 	) | ||||||
|  | @ -52,13 +52,14 @@ func Handler(img []byte) (byte, []byte) { | ||||||
| 	//} else {
 | 	//} else {
 | ||||||
| 	//	fmt.Println("GO: Run bindgen -- infer FAILED")
 | 	//	fmt.Println("GO: Run bindgen -- infer FAILED")
 | ||||||
| 	//}
 | 	//}
 | ||||||
|  | 	id := atomic.AddUint64(&counter, 1) | ||||||
| 	str := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) | 	str := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) | ||||||
| 	tick := time.Now().Format("20060102150405") + str[10:] | 	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
 | 	// print logs
 | ||||||
| 	hash := genSha1(img) | 	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 | 	return 0x11, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue