Go实战--golang实现MP4视频文件服务器(nareix/joy4)
2017-09-21 16:38
3195 查看
生命不止,继续 go go go !!!
有点忙,有点懈怠,继续。
关于golang实现的静态文件服务器之前有写过:
Go实战–golang实现静态文件服务器(文件查看,文件上传,文件下载)
正好,最近在做视频方面的东西,那么先来个简单的,实现一个提供mp4视频文件的服务器吧,并且通过浏览器访问播放。
我们先浅尝辄止,简单使用一下:
输出:
AAC 48000 FLTP 1ch
H264 960 720
有点忙,有点懈怠,继续。
关于golang实现的静态文件服务器之前有写过:
Go实战–golang实现静态文件服务器(文件查看,文件上传,文件下载)
正好,最近在做视频方面的东西,那么先来个简单的,实现一个提供mp4视频文件的服务器吧,并且通过浏览器访问播放。
MP4文件服务器
package main import ( "log" "net/http" "os" "time" ) func ServeHTTP(w http.ResponseWriter, r *http.Request) { video, err := os.Open("./test.mp4") if err != nil { log.Fatal(err) } defer video.Close() http.ServeContent(w, r, "test.mp4", time.Now(), video) } func main() { http.HandleFunc("/", ServeHTTP) http.ListenAndServe(":8080", nil) }
package main import "io/ioutil" import "log" import "net/http" import "strings" type viewHandler struct{} func (vh *viewHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { path := r.URL.Path[1:] data, err := ioutil.ReadFile(string(path)) if err != nil { log.Printf("Error with path %s: %v", path, err) w.WriteHeader(404) w.Write([]byte("404")) } if strings.HasSuffix(path, ".html") { w.Header().Add("Content-Type", "text/html") } else if strings.HasSuffix(path, ".mp4") { w.Header().Add("Content-Type", "video/mp4") } w.Write(data) } func main() { http.Handle("/", new(viewHandler)) http.ListenAndServe(":8080", nil) }
nareix/joy4
Golang audio/video library and streaming server我们先浅尝辄止,简单使用一下:
package main import ( "fmt" "github.com/nareix/joy4/av" "github.com/nareix/joy4/av/avutil" "github.com/nareix/joy4/format" ) func init() { format.RegisterAll() } func main() { file, _ := avutil.Open("test.mp4") streams, _ := file.Streams() for _, stream := range streams { if stream.Type().IsAudio() { astream := stream.(av.AudioCodecData) fmt.Println(astream.Type(), astream.SampleRate(), astream.SampleFormat(), astream.ChannelLayout()) } else if stream.Type().IsVideo() { vstream := stream.(av.VideoCodecData) fmt.Println(vstream.Type(), vstream.Width(), vstream.Height()) } } file.Close() }
输出:
AAC 48000 FLTP 1ch
H264 960 720
相关文章推荐
- Go实战--golang实现生成缩略图服务器(disintegration/imaging、nfnt/resize)
- Go实战--golang实现静态文件服务器(文件查看,文件上传,文件下载)
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- Mp4v2实现h264+aac打包成Mp4视频文件
- javaCV开发详解之3:收流器实现,录制流媒体服务器的rtsp/rtmp视频文件(基于javaCV-FFMPEG)
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- goAhead上实现文件上传到嵌入式web服务器上
- 手机默认录制视频生成mp4文件,现在准备上传到服务器,网上有什么好的开源压缩框架吗?不压缩文件太大
- golangphp--GO解析PHP源码并实现一个miniPHP服务器
- Android-->MediaMuxer,MediaCodec,AudioRecord及Camera实现音频视频混合MP4文件
- javaCV开发详解之3:收流器实现,录制流媒体服务器的rtsp/rtmp视频文件(基于javaCV-FFMPEG)
- goAhead上实现文件上传到嵌入式web服务器上
- golang实现简单文件服务器
- javaCV开发详解之3:收流器实现,录制流媒体服务器的rtsp/rtmp视频文件(基于javaCV-FFMPEG)
- Jetty实战之 嵌入式运行Jetty实现简单文件服务器
- android 实现提交视频文件到服务器
- goAhead上实现文件上传到嵌入式web服务器上
- Mp4v2实现h264+aac打包成Mp4视频文件
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- goAhead上实现文件上传到嵌入式web服务器上