nareix / joy4

Golang audio/video library and streaming server
MIT License
2.66k stars 501 forks source link

Feature request: possibility to demux UDP MPEG-TS packets #50

Open phsm opened 6 years ago

phsm commented 6 years ago

I'm trying to demux MPEG-TS over UDP.

Code is something like that:

addr, err := net.ResolveUDPAddr("udp", "239.1.2.3:1234")
if err != nil {
    log.Fatalln(err)
}

conn, err := net.ListenMulticastUDP("udp", nil, addr)
if err != nil {
    log.Fatalln(err)
}

demux := ts.NewDemuxer(conn)
streams, err := demux.Streams()
if err != nil {
    fmt.Printf("error getting streams: %s\n", err)
    os.Exit(1)
}

It doesn't seem to work correctly. I've looked through the formats/ts and formats/ts/tsio packages: the clue is, that TSReadPacket wants to have the pure sequence of MPEG-TS packets in the stream.

But when you join multicast stream, you never know which part of it you have started to receive. I mean, you can join in the middle of the packet. In this case, TS parser should read the stream until it encounters a valid beginning of the new MPEG-TS packet.

I could try to implement it by myself, but some piece of advice from the author how to do it properly will be really appreciated.