golang - Serve a video with golang, 동영상, 미디어 파일 오픈, 열어서 브라우저에 보여주기, mp4
이 름 : 바다아이
|
조회수 : 9752
짧은 주소 : https://www.bada-ie.com/su/?101591924971
미디어 스트리밍의 원리가 되겠네요... ^^;
요즘 대부분 브라우저가 html5 가 지원되니까요....
그리고 각종 미디어 플레이어들이 스트리밍을 잘 지원하니까..
아래를 참고하면 간단하게 스트리밍 서버를 만들 수 있습니다.
In my last two posts I've shown how to generate a mp4 video file.
In this post I show some go code to serve the generated file via http.
It basically boils down to a call of ServeContent in the http package.
package main
import (
"flag""log""net/http""os""path""time"
)
func main() {
fileName := flag.String("f","","filename to stream")
flag.Parse()
if fileName==nil || *fileName=="" {
log.Println("File needed")
return
}
baseName := path.Base(*fileName)
file,err := os.Open(*fileName)
iferr!=nil {
log.Println("Couldn't open file",fileName)
return
}
http.HandleFunc("/stream",func(w http.ResponseWriter, r *http.Request) {
http.ServeContent(w,r,baseName,time.Unix(0,0),file)
})
log.Fatal(http.ListenAndServe(":8010",nil))
}
To start the programtype ./prog -f cool_movie.mp4 and then enter
http://192.168.0.1:8010/stream in a browser on your smartphone
(assuming you PC has the IP 192.168.0.1). I've tested it with Firefox and Chrome.
Both could play the file but Firefox has no full screen mode and thus leaves
the navigation bars active. A resized and shrinked video isn't what you want when playing
around with cardboard VR.
출처 : https://jluger.de/blog/20160118_serve_a_video_with_golang.html
|
|
번 호
카테고리
제 목
이름
조회수
Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천 실행시간 : 0.2013 초 to webmaster... gogo sea. gogo sea.