go-astits:在GO中本地解复用和复用MPEG传输流(.ts)

  • q4_348339
    了解作者
  • 3MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-27 05:36
    上传日期
这是一个Golang库,用于在GO中本地解复用和复用MPEG传输流(ts)。 警告:该库尚未投入生产。 使用风险自负! 安装 要安装该库,请使用以下命令: go get -u github.com/asticode/go-astits/... 在看代码之前... 传输流由数据包组成。 每个数据包都有一个报头,一个可选的适配字段和一个有效负载。 可以将几个有效负载附加并解析为数据。 TRANSPORT STREAM +--------------------------------------------------------------------------------------------------+ |
go-astits-master.zip
  • go-astits-master
  • packet_test.go
    9.1KB
  • .travis.yml
    310B
  • clock_reference.go
    734B
  • dvb.go
    4KB
  • descriptor_test.go
    22.8KB
  • data_tot_test.go
    610B
  • cmd
  • astits-es-split
  • main.go
    4KB
  • astits-probe
  • main.go
    14.1KB
  • packet_pool_test.go
    2.8KB
  • packet_buffer.go
    3.3KB
  • packet_buffer_test.go
    858B
  • data_eit_test.go
    1.4KB
  • data_sdt_test.go
    1.2KB
  • data_pmt.go
    7.2KB
  • muxer_test.go
    8.6KB
  • program_map.go
    1KB
  • data_pes_test.go
    14.7KB
  • clock_reference_test.go
    321B
  • demuxer_test.go
    5.1KB
  • LICENSE
    1KB
  • data_tot.go
    913B
  • data_pes.go
    18.9KB
  • data_nit_test.go
    1.1KB
  • crc32.go
    542B
  • data_pmt_test.go
    1.9KB
  • data_test.go
    1.9KB
  • data_sdt.go
    3KB
  • data_psi.go
    17.2KB
  • data_psi_test.go
    12.9KB
  • doc
  • en_300468v011501p.pdf
    3.6MB
  • data_nit.go
    2.2KB
  • program_map_test.go
    258B
  • .gitignore
    39B
  • demuxer.go
    4.8KB
  • descriptor.go
    59.1KB
  • data_eit.go
    3.2KB
  • go.sum
    1.3KB
  • packet_pool.go
    3.5KB
  • README.md
    5.8KB
  • data.go
    2.9KB
  • packet.go
    15.2KB
  • muxer.go
    10.1KB
  • data_pat.go
    1.6KB
  • data_pat_test.go
    1.6KB
  • dvb_test.go
    1.9KB
  • wrapping_counter.go
    360B
  • go.mod
    166B
内容介绍
[![GoReportCard](http://goreportcard.com/badge/github.com/asticode/go-astits)](http://goreportcard.com/report/github.com/asticode/go-astits) [![GoDoc](https://godoc.org/github.com/asticode/go-astits?status.svg)](https://godoc.org/github.com/asticode/go-astits) [![Travis](https://travis-ci.org/asticode/go-astits.svg?branch=master)](https://travis-ci.org/asticode/go-astits#) [![Coveralls](https://coveralls.io/repos/github/asticode/go-astits/badge.svg?branch=master)](https://coveralls.io/github/asticode/go-astits) This is a Golang library to natively demux and mux MPEG Transport Streams (ts) in GO. WARNING: this library is not yet production ready. Use at your own risks! # Installation To install the library use the following: go get -u github.com/asticode/go-astits/... # Before looking at the code... The transport stream is made of packets.<br> Each packet has a header, an optional adaptation field and a payload.<br> Several payloads can be appended and parsed as a data. ``` TRANSPORT STREAM +--------------------------------------------------------------------------------------------------+ | | PACKET PACKET +----------------------------------------------+----------------------------------------------+---- | | | +--------+---------------------------+---------+--------+---------------------------+---------+ | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | ... +--------+---------------------------+---------+--------+---------------------------+---------+ | | | | +---------+ +---------+ | | +----------------------------------------------+ DATA ``` # Using the library in your code WARNING: the code below doesn't handle errors for readability purposes. However you SHOULD! ## Demux ```go // Create a cancellable context in case you want to stop reading packets/data any time you want ctx, cancel := context.WithCancel(context.Background()) // Handle SIGTERM signal ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGTERM) go func() { <-ch cancel() }() // Open your file or initialize any kind of io.Reader // Buffering using bufio.Reader is recommended for performance f, _ := os.Open("/path/to/file.ts") defer f.Close() // Create the demuxer dmx := astits.NewDemuxer(ctx, f) for { // Get the next data d, _ := dmx.NextData() // Data is a PMT data if d.PMT != nil { // Loop through elementary streams for _, es := range d.PMT.ElementaryStreams { fmt.Printf("Stream detected: %d\n", es.ElementaryPID) } return } } ``` ## Mux ```go // Create a cancellable context in case you want to stop writing packets/data any time you want ctx, cancel := context.WithCancel(context.Background()) // Handle SIGTERM signal ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGTERM) go func() { <-ch cancel() }() // Create your file or initialize any kind of io.Writer // Buffering using bufio.Writer is recommended for performance f, _ := os.Create("/path/to/file.ts") defer f.Close() // Create the muxer mx := astits.NewMuxer(ctx, f) // Add an elementary stream mx.AddElementaryStream(astits.PMTElementaryStream{ ElementaryPID: 1, StreamType: astits.StreamTypeMetadata, }) // Write tables // Using that function is not mandatory, WriteData will retransmit tables from time to time mx.WriteTables() // Write data mx.WriteData(&astits.MuxerData{ PES: &astits.PESData{ Data: []byte("test"), }, PID: 1, }) ``` ## Options In order to pass options to the demuxer or the muxer, look for the methods prefixed with `DemuxerOpt` or `MuxerOpt` and add them upon calling `NewDemuxer` or `NewMuxer` : ```go // This is your custom packets parser p := func(ps []*astits.Packet) (ds []*astits.Data, skip bool, err error) { // This is your logic skip = true return } // Now you can create a demuxer with the proper options dmx := NewDemuxer(ctx, f, DemuxerOptPacketSize(192), DemuxerOptPacketsParser(p)) ``` # CLI This library provides 2 CLIs that will automatically get installed in `GOPATH/bin` on `go get` execution. ## astits-probe ### List streams $ astits-probe -i <path to your file> -f <format: text|json (default: text)> ### List packets $ astits-probe packets -i <path to your file> ### List data $ astits-probe data -i <path to your file> -d <data type: eit|nit|... (repeatable argument | if empty, all data types are shown)> ## astits-es-split ### Split streams into separate .ts files $ astits-es-split <path to your file> -o <path to output dir> # Features and roadmap - [x] Add demuxer - [x] Add muxer - [x] Demux PES packets - [x] Mux PES packets - [x] Demux PAT packets - [x] Mux PAT packets - [x] Demux PMT packets - [x] Mux PMT packets - [x] Demux EIT packets - [ ] Mux EIT packets - [x] Demux NIT packets - [ ] Mux NIT packets - [x] Demux SDT packets - [ ] Mux SDT packets - [x] Demux TOT packets - [ ] Mux TOT packets - [ ] Demux BAT packets - [ ] Mux BAT packets - [ ] Demux DIT packets - [ ] Mux DIT packets - [ ] Demux RST packets - [ ] Mux RST packets - [ ] Demux SIT packets - [ ] Mux SIT packets - [ ] Mux ST packets - [ ] Demux TDT packets - [ ] Mux TDT packets - [ ] Demux TSDT packets - [ ] Mux TSDT packets
评论
    相关推荐