1 回答
TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
GO / CGO有一些特質(zhì),你在這里碰到:
type OutputFormat C.struct_AVOutputFormat是 go 類型聲明,而不是別名。將其視為薄包裝而不是別名可能會(huì)有所幫助。因此,C.struct_AVOutputFormat字段不會(huì)導(dǎo)出,這就是您獲得OutputFormat != C.struct_AVOutputFormatERROR: outputF.audio_codec undefined (cannot refer to unexported field or method audio_codec)
如果該字段被調(diào)用Audio_codec它將符合go對(duì)導(dǎo)出標(biāo)識(shí)符的定義,我們可以訪問它,但事實(shí)并非如此。
有一種方法可以解決這個(gè)問題,但我建議在繼續(xù)之前三思而后行,因?yàn)樗褂貌话踩闹羔?,并且您的程序可能?huì)在運(yùn)行時(shí)失去可移植性和/或穩(wěn)定性。如果您想了解更多信息,這是不安全指針的良好介紹。
現(xiàn)在,如果您確實(shí)確定要執(zhí)行此操作,解決方案是將指針轉(zhuǎn)換為不安全的指針,然后將其轉(zhuǎn)換為指向 的指針。請(qǐng)注意,這需要您加載 FFMPEG 標(biāo)頭才能獲得OutputFormatC.struct_AVOutputFormatC.struct_AVOutputFormat
//#cgo pkg-config: libavformat
//#include <libavformat/avformat.h>
import "C"
import (
"fmt"
"unsafe"
"github.com/giorgisio/goav/avformat"
)
func getOutput() *avformat.OutputFormat {
// calls out to avformat and gets an OutputFormat back
}
func main() {
outputF := getOutput()
coutput := *(*C.struct_AVOutputFormat)(unsafe.Pointer(outputF))
fmt.Println(coutput.audio_codec) // This should now work
}
警告:我還沒有測試cgo包配置和導(dǎo)入是否正確,但這適用于一個(gè)簡單的C庫,我站起來嘗試一下。<libavformat/avformat.h>
- 1 回答
- 0 關(guān)注
- 154 瀏覽
添加回答
舉報(bào)
