-
-
Save Hakkin/6cab34dcf004494d436025a1846633c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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