Comments (8)
ups..., thanks a lot! this is very powerful !!
from joy4.
thanks, I'll check it
from joy4.
there's a closure bug:
for i := range streamMap {
go func(i int) {
err := pushStream(que, streamMap[i], wait)
if err != nil {
log.Println(err)
}
}(i)
}
from joy4.
and wait should start before go func():
for i := range streamMap {
wait.Add(1)
go func(i int) {
err := pushStream(que, streamMap[i], wait)
if err != nil {
log.Println(err)
}
}(i)
}
from joy4.
Using OBS studio sometimes i get a data race report with -race enabled
WARNING: DATA RACE
Write at 0x00c420078670 by main goroutine:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:107 +0x2b2
main.proxyServer()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:79 +0xa7
main.main()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:24 +0x2f
Previous write at 0x00c420078670 by goroutine 6:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe.func1()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:118 +0x81
Goroutine 6 (finished) created at:
github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe()
/home/thesyncim/gocode/src/github.com/nareix/joy4/format/rtmp/rtmp.go:122 +0xa6f
main.proxyServer()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:79 +0xa7
main.main()
/home/thesyncim/gocode/src/github.com/thesyncim/exp/rtmp/proxy.go:24 +0x2f
from joy4.
using the code from example above i'm unable to push a stream to youtube/srs server (only go-oryx
can handle the stream).
wireshark file:
push_youtube.pcapng.zip
from joy4.
fixed datarace 4918d07
from joy4.
you can replicate the issue with:
ffmpeg -re -i bbb_sunflower_1080p_60fps_normal.mp4 -c:v libx264 -b:v 2M -pix_fmt yuv420p -c
package main
import (
"log"
"strings"
"sync"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/av/pubsub"
"github.com/nareix/joy4/format"
"github.com/nareix/joy4/format/rtmp"
)
func init() {
format.RegisterAll()
log.SetFlags(log.Lshortfile|log.Ltime)
}
var sm = map[string][]string{
"azorestv": []string{"rtmp://opinion.azorestv.com:1936/live/test"},
}
func main() {
proxyServer()
}
func proxyServer() {
server := &rtmp.Server{}
//rtmp.Debug=true
server.HandlePublish = func(conn *rtmp.Conn) {
segs := strings.Split(conn.URL.Path, "/")
key := segs[2]
streamMap, ok := sm[key]
if !ok {
log.Println("invalid key")
return
}
que := &pubsub.Queue{}
streams, err := conn.Streams()
if err != nil {
log.Println(err)
return
}
que = pubsub.NewQueue(streams)
wait := &sync.WaitGroup{}
for i := range streamMap {
wait.Add(1)
go func(i int,que *pubsub.Queue,wait *sync.WaitGroup) {
err := pushStream(que, streamMap[i], wait)
if err != nil {
log.Println(err)
}
}(i,que,wait)
}
go avutil.CopyPackets(que, conn)
wait.Wait()
}
server.ListenAndServe()
}
func pushStream(sub *pubsub.Queue, dsturl string, wait *sync.WaitGroup) error {
defer wait.Done()
origin := sub.Latest()
dst, err := rtmp.Dial(dsturl)
if err != nil {
return err
}
defer dst.Close()
return avutil.CopyFile(dst, origin)
}
feel free to use this server(srs 3.0) to debug the issue
thank you
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.