Skip to content

Commit

Permalink
search for first h264 video stream
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromoreira committed May 14, 2024
1 parent 6e25c86 commit a059a72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions astiav_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (h *helper) inputFirstPacket(name string) (pkt *Packet, err error) {
return
}

func (h *helper) inputFirstPacketWithBitStreamFilter(name string, fn string) (pkt *Packet, err error) {
func (h *helper) inputFirstVideoPacketWithBitStreamFilter(name string, fn string) (pkt *Packet, err error) {
var fc *FormatContext
if fc, err = h.inputFormatContext(name); err != nil {
err = fmt.Errorf("astiav_test: getting input format context failed")
Expand All @@ -168,14 +168,32 @@ func (h *helper) inputFirstPacketWithBitStreamFilter(name string, fn string) (pk
return
}
h.closer.Add(pkt.Free)
var foundVideo bool

if err = fc.ReadFrame(pkt); err != nil {
err = fmt.Errorf("astiav_test: reading frame failed: %w", err)
for {
if err = fc.ReadFrame(pkt); err != nil {
err = fmt.Errorf("astiav_test: reading frame failed: %w", err)
return
}

for _, s := range fc.Streams() {
if s.Index() == pkt.StreamIndex() && s.CodecParameters().CodecID() == CodecIDH264 {
foundVideo = true
break
}
}
if foundVideo {
break
}
}

if !foundVideo {
err = fmt.Errorf("astiav_test: there must be an h264 stream")
pkt = nil
return
}

var bsfc *BitStreamFilterContext

bsfc, err = h.bitStreamFilterContext(fc, pkt.StreamIndex(), fn)
if err != nil {
pkt = nil
Expand Down
2 changes: 1 addition & 1 deletion bit_stream_filter_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestBitStreamFilterContext(t *testing.T) {

// video.mp4 bit stream h264 format is avcc
pkt1, err := globalHelper.inputFirstPacket("video.mp4")
pkt1Bsf, errBsf := globalHelper.inputFirstPacketWithBitStreamFilter("video.mp4", "h264_mp4toannexb")
pkt1Bsf, errBsf := globalHelper.inputFirstVideoPacketWithBitStreamFilter("video.mp4", "h264_mp4toannexb")
require.NoError(t, err)
require.NoError(t, errBsf)

Expand Down

0 comments on commit a059a72

Please sign in to comment.