Exemple #1
0
func extract(fname string, outdir string, pid int) {
	var pkts chan *ts.TsPkt
	pkts = ts.ParseFile(fname)

	of := filepath.Join(outdir, strconv.Itoa(pid)+".es")
	f, err := os.Create(of)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	for pkt := range pkts {
		if pkt.Pid == pid {
			f.Write(pkt.Data)
		}
	}
}
Exemple #2
0
func parse(fname string, outdir string, psiOnly bool) {
	var pkts chan *ts.TsPkt

	Root = outdir

	// PCR PID -> PCR values
	var progPcrList = make(map[int][]ts.PcrInfo)
	var extraPcrList = make(map[int][]ts.PcrInfo)

	pkts = ts.ParseFile(fname)
	psiParser := ts.NewPsiParser()
	for pkt := range pkts {
		if ok := psiParser.Parse(pkt); ok {
			break
		}
	}
	psiParser.Finish()
	psiParser.Report(outdir)

	if psiOnly {
		return
	}

	streams := psiParser.GetStreams()

	pcrs := psiParser.GetPcrs()
	for pcrPid, _ := range pcrs {
		// Default PCR list length: 1500 = 25Hz * 60s
		progPcrList[pcrPid] = make([]ts.PcrInfo, 0)
	}

	records := make(map[int]ts.Record)
	for pid, s := range streams {
		records[pid] = ts.CreateRecord(pid, ts.GetStreamType(s), outdir)
	}

	pkts = ts.ParseFile(fname)
	for pkt := range pkts {
		if pcr, ok := pkt.PCR(); ok {
			if pids, ok := pcrs[pkt.Pid]; ok {
				// Save the PCR value
				progPcrList[pkt.Pid] = append(
					progPcrList[pkt.Pid],
					ts.PcrInfo{pkt.Pos, pcr})
				for _, pid := range pids {
					records[pid].NotifyTime(pcr, pkt.Pos)
				}
			} else {
				// extra PCR
				if _, ok := extraPcrList[pkt.Pid]; !ok {
					extraPcrList[pkt.Pid] = make([]ts.PcrInfo, 0)
				}
				extraPcrList[pkt.Pid] = append(
					extraPcrList[pkt.Pid],
					ts.PcrInfo{pkt.Pos, pcr})
			}
		}

		if record, ok := records[pkt.Pid]; ok {
			record.Process(pkt)
		}
	}

	for pcrPid, pcrList := range progPcrList {
		ts.CheckPcrInterval(outdir, "", pcrPid, pcrList)
	}

	for pcrPid, pcrList := range extraPcrList {
		ts.CheckPcrInterval(outdir, "extra", pcrPid, pcrList)
	}

	for _, record := range records {
		record.Flush()
		record.Report(outdir)
	}

	// verify(psiParser.Info)
}