yapingcat / gomedia

golang library for rtmp, mpeg-ts,mpeg-ps,flv,mp4,ogg,rtsp
MIT License
415 stars 71 forks source link

这里有个bug,应该是一个宽、一个高 #160

Open orestonce opened 3 weeks ago

orestonce commented 3 weeks ago

现在是2个都保存为宽了 https://github.com/yapingcat/gomedia/blob/17feea57090c9753003bc108ddd45d491a26b7b3/go-codec/h264.go#L489

orestonce commented 3 weeks ago

还有2个关联的问题:

  1. 能否解析出 ffmpeg 输出的 [SAR 1:1 DAR 16:9] 信息?
  2. 目前解析出的SarWidth是0,数据应该不对 00451.zip
    func GetTsVideoInfo(tsPath string) (info TsVideoInfo) {
    demuxer := mpeg2.NewTSDemuxer()
    demuxer.OnFrame = func(cid mpeg2.TS_STREAM_TYPE, frame []byte, pts uint64, dts uint64) {
        if cid == mpeg2.TS_STREAM_H264 {
            codec.SplitFrameWithStartCode(frame, func(nalu []byte) bool {
                naluType := codec.H264NaluType(nalu)
                if naluType == codec.H264_NAL_SPS {
                    info.Width, info.Height = codec.GetH264Resolution(nalu)
                    start, sc := codec.FindStartCode(nalu, 0)
                    sodb := codec.CovertRbspToSodb(nalu[start+int(sc)+1:])
                    bs := codec.NewBitStream(sodb)
                    var s codec.SPS
                    s.Decode(bs)
                    if s.VuiParameters.NumUnitsInTick > 0 {
                        info.Fps = int(s.VuiParameters.TimeScale / s.VuiParameters.NumUnitsInTick / 2)
                    }
                    info.Sar = int(s.VuiParameters.SarWidth) // 这里是0
                    return false
                }
                return true
            })
        }
    }