Comments (1)
It seems to be possible to use ts.Demuxer with http server.
Here is a modified streaming server example (i didnt test it thoroughly so it is up to you)
package main
import (
"sync"
"io"
"net/http"
"github.com/nareix/joy4/format"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/av/pubsub"
"github.com/nareix/joy4/format/rtmp"
"github.com/nareix/joy4/format/flv"
"github.com/nareix/joy4/format/ts"
)
func init() {
format.RegisterAll()
}
func main() {
server := &rtmp.Server{}
l := &sync.RWMutex{}
type Channel struct {
que *pubsub.Queue
}
channels := map[string]*Channel{}
server.HandlePlay = func(conn *rtmp.Conn) {
l.RLock()
ch := channels[conn.URL.Path]
l.RUnlock()
if ch != nil {
cursor := ch.que.Latest()
avutil.CopyFile(conn, cursor)
}
}
server.HandlePublish = func(conn *rtmp.Conn) {
streams, _ := conn.Streams()
l.Lock()
ch := channels[conn.URL.Path]
if ch == nil {
ch = &Channel{}
ch.que = pubsub.NewQueue()
ch.que.WriteHeader(streams)
channels[conn.URL.Path] = ch
} else {
ch = nil
}
l.Unlock()
if ch == nil {
return
}
avutil.CopyPackets(ch.que, conn)
l.Lock()
delete(channels, conn.URL.Path)
l.Unlock()
ch.que.Close()
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
l.RLock()
ch := channels[r.URL.Path]
l.RUnlock()
if ch != nil {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Transfer-Encoding", "chunked")
w.WriteHeader(200)
muxer := ts.NewMuxer(w)
cursor := ch.que.Latest()
avutil.CopyFile(muxer, cursor)
} else {
http.NotFound(w, r)
}
})
go http.ListenAndServe(":8089", nil)
server.ListenAndServe()
// ffmpeg -re -i movie.flv -c copy -f flv rtmp://localhost/movie
// ffplay http://localhost:8089/movie <- that should be MPEG-TS over plain HTTP
}
from joy4.
Related Issues (20)
- How to get FPS?
- How to transcode to VP9 on the fly?
- How to produce fragmented mp4 files? HOT 5
- How to send error to client? HOT 3
- How to use authentication?
- read/write > 4GB size fail
- Extract frame and save to image file
- It doesn't support publish mp3 now
- fatal error: libavresample/avresample.h: No such file or directory HOT 1
- How do I save RTPS streams as MP4 video files?
- could not determine kind of name for C.avcodec_encode_audio2
- Any plans moving forward? HOT 1
- fatal error: libavformat/avformat.h: No such file or directory HOT 2
- FFMPEG RTMP Stream Loop Option? HOT 1
- Invalid memory address or nil pointer dereference in Transcoding example code
- why user authentication set to nil?
- Can you support H265 codec? HOT 1
- rtmp_publish example does not working
- Exception Handling About RTMP server HOT 1
- User disconnection handler HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joy4.