mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-07 00:52:48 +08:00
Minor changes
This commit is contained in:
8
codec.go
8
codec.go
@@ -101,19 +101,15 @@ func FindEncoderByName(n string) *Codec {
|
|||||||
return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
|
return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Codec) HardwareConfigs(dt HardwareDeviceType) []CodecHardwareConfig {
|
func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareConfig) {
|
||||||
var configs []CodecHardwareConfig
|
|
||||||
var i int
|
var i int
|
||||||
|
|
||||||
for {
|
for {
|
||||||
config := C.avcodec_get_hw_config(c.c, C.int(i))
|
config := C.avcodec_get_hw_config(c.c, C.int(i))
|
||||||
if config == nil {
|
if config == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
configs = append(configs, CodecHardwareConfig{c: config})
|
configs = append(configs, CodecHardwareConfig{c: config})
|
||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return configs
|
return
|
||||||
}
|
}
|
||||||
|
@@ -8,8 +8,8 @@ import "C"
|
|||||||
type CodecHardwareConfigMethodFlag int
|
type CodecHardwareConfigMethodFlag int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CodecHardwareConfigMethodAdHoc = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_AD_HOC)
|
CodecHardwareConfigMethodFlagAdHoc = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_AD_HOC)
|
||||||
CodecHardwareConfigMethodHwDeviceCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
|
CodecHardwareConfigMethodFlagHwDeviceCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
|
||||||
CodecHardwareConfigMethodHwFramesCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX)
|
CodecHardwareConfigMethodFlagHwFramesCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX)
|
||||||
CodecHardwareConfigMethodInternal = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_INTERNAL)
|
CodecHardwareConfigMethodFlagInternal = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_INTERNAL)
|
||||||
)
|
)
|
||||||
|
@@ -78,8 +78,6 @@ func main() {
|
|||||||
// Loop through streams
|
// Loop through streams
|
||||||
streams := make(map[int]*stream) // Indexed by input stream index
|
streams := make(map[int]*stream) // Indexed by input stream index
|
||||||
for _, is := range inputFormatContext.Streams() {
|
for _, is := range inputFormatContext.Streams() {
|
||||||
var err error
|
|
||||||
|
|
||||||
// Only process video
|
// Only process video
|
||||||
if is.CodecParameters().MediaType() != astiav.MediaTypeVideo {
|
if is.CodecParameters().MediaType() != astiav.MediaTypeVideo {
|
||||||
continue
|
continue
|
||||||
@@ -105,7 +103,7 @@ func main() {
|
|||||||
// Loop through codec hardware configs
|
// Loop through codec hardware configs
|
||||||
for _, p := range hardwareConfigs {
|
for _, p := range hardwareConfigs {
|
||||||
// Valid hardware config
|
// Valid hardware config
|
||||||
if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType {
|
if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodFlagHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType {
|
||||||
s.hardwarePixelFormat = p.PixelFormat()
|
s.hardwarePixelFormat = p.PixelFormat()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -122,6 +120,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create hardware device context
|
// Create hardware device context
|
||||||
|
var err error
|
||||||
s.hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, "", nil)
|
s.hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))
|
log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))
|
||||||
|
Reference in New Issue
Block a user