Skip to content

Commit

Permalink
codec_context.go and format_context.go (#111)
Browse files Browse the repository at this point in the history
* Update codec_context.go

HardwareFrameContext

* Update format_context.go

DumpFormat and HardwareFrameContext

* fix with same convention

* fix with same convention

* fix with same convention

* fix with same convention
  • Loading branch information
oldma3095 authored Nov 26, 2024
1 parent c9d8c33 commit 299b04b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions codec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
}
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3bac44bb0b016ab838780cc19ac277d6
func (cc *CodecContext) HardwareFrameContext() *HardwareFrameContext {
return newHardwareFrameContextFromC(cc.c.hw_frames_ctx)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3bac44bb0b016ab838780cc19ac277d6
func (cc *CodecContext) SetHardwareFrameContext(hfc *HardwareFrameContext) {
if cc.hfc != nil {
Expand Down
14 changes: 14 additions & 0 deletions format_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,17 @@ func (fc *FormatContext) FindBestStream(mt MediaType, wantedStreamIndex, related
}
return nil, nil, fmt.Errorf("astiav: no stream with index %d", ret)
}

// https://ffmpeg.org/doxygen/7.0/group__lavf__misc.html#gae2645941f2dc779c307eb6314fd39f10
func (fc *FormatContext) Dump(streamIndex int, url string, isOutput bool) {
curl := (*C.char)(nil)
if len(url) > 0 {
curl = C.CString(url)
defer C.free(unsafe.Pointer(curl))
}
cisOutput := 0
if isOutput {
cisOutput = 1
}
C.av_dump_format(fc.c, C.int(streamIndex), curl, C.int(cisOutput))
}
10 changes: 10 additions & 0 deletions format_context_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package astiav

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,6 +36,15 @@ func TestFormatContext(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=Big Buck Bunny\r\nt=0 0\r\na=tool:libavformat 61.1.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:441\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LADasgKDPz4CIAAAMAAgAAAwBhHihUkA==,aM48gA==; profile-level-id=42C00D\r\na=control:streamid=0\r\nm=audio 0 RTP/AVP 97\r\nb=AS:161\r\na=rtpmap:97 MPEG4-GENERIC/48000/2\r\na=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190\r\na=control:streamid=1\r\n", sdp)

SetLogLevel(LogLevelInfo)
SetLogCallback(func(c Classer, l LogLevel, f, msg string) {
msg = strings.TrimSpace(msg)
if strings.HasPrefix(msg, "Stream") && strings.Contains(msg, "Video") {
require.Equal(t, msg, `Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 320x180 [SAR 1:1 DAR 16:9], 441 kb/s, 24 fps, 24 tbr, 12288 tbn (default)`)
}
})
fc1.Dump(0, "video.mp4", false)

_, _, err = fc1.FindBestStream(MediaTypeUnknown, -1, -1)
require.Error(t, err)
s2, c1, err := fc1.FindBestStream(MediaTypeVideo, -1, -1)
Expand Down

0 comments on commit 299b04b

Please sign in to comment.