Skip to content

Instantly share code, notes, and snippets.

@Hakkin

Hakkin/main.go Secret

Last active September 25, 2019 23:35
Show Gist options
  • Save Hakkin/6cab34dcf004494d436025a1846633c0 to your computer and use it in GitHub Desktop.
Save Hakkin/6cab34dcf004494d436025a1846633c0 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"context"
"fmt"
"io"
"os"
"github.com/asticode/go-astits"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("supply input filename")
os.Exit(1)
}
input := os.Args[1]
tsFile, err := os.Open(input)
if err != nil {
panic(err)
}
defer tsFile.Close()
dmx := astits.New(context.Background(), tsFile)
pidFiles := make(map[uint16]io.Writer)
var d *astits.Data
for {
if d, err = dmx.NextData(); err != nil {
if err == astits.ErrNoMorePackets {
break
}
panic(err)
}
if d.PES == nil {
continue
}
pidWriter, ok := pidFiles[d.PID]
if !ok {
pidFile, err := os.Create(fmt.Sprintf("%d", d.PID))
if err != nil {
panic(err)
}
defer pidFile.Close()
pidFiles[d.PID] = bufio.NewWriter(pidFile)
pidWriter = pidFiles[d.PID]
}
_, err = pidWriter.Write(d.PES.Data)
if err != nil {
panic(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment