mirror of
https://github.com/asticode/go-astiav.git
synced 2025-09-28 04:52:12 +08:00
Hardware filtering example now shows how to set filters hardware device context
This commit is contained in:
@@ -28,6 +28,7 @@ var (
|
|||||||
decodedHardwareFrame *astiav.Frame
|
decodedHardwareFrame *astiav.Frame
|
||||||
filterGraph *astiav.FilterGraph
|
filterGraph *astiav.FilterGraph
|
||||||
filteredHardwareFrame *astiav.Frame
|
filteredHardwareFrame *astiav.Frame
|
||||||
|
hardwareDeviceContext *astiav.HardwareDeviceContext
|
||||||
inputStream *astiav.Stream
|
inputStream *astiav.Stream
|
||||||
softwareFrame *astiav.Frame
|
softwareFrame *astiav.Frame
|
||||||
)
|
)
|
||||||
@@ -94,7 +95,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop through streams
|
// Loop through streams
|
||||||
var hdc *astiav.HardwareDeviceContext
|
|
||||||
hardwarePixelFormat := astiav.PixelFormatNone
|
hardwarePixelFormat := astiav.PixelFormatNone
|
||||||
for _, is := range inputFormatContext.Streams() {
|
for _, is := range inputFormatContext.Streams() {
|
||||||
// Only process video
|
// Only process video
|
||||||
@@ -143,13 +143,13 @@ func main() {
|
|||||||
|
|
||||||
// Create hardware device context
|
// Create hardware device context
|
||||||
var err error
|
var err error
|
||||||
if hdc, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, *hardwareDeviceName, nil, 0); err != nil {
|
if hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, *hardwareDeviceName, nil, 0); 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))
|
||||||
}
|
}
|
||||||
c.Add(hdc.Free)
|
c.Add(hardwareDeviceContext.Free)
|
||||||
|
|
||||||
// Update decoder context
|
// Update decoder context
|
||||||
decCodecContext.SetHardwareDeviceContext(hdc)
|
decCodecContext.SetHardwareDeviceContext(hardwareDeviceContext)
|
||||||
decCodecContext.SetPixelFormatCallback(func(pfs []astiav.PixelFormat) astiav.PixelFormat {
|
decCodecContext.SetPixelFormatCallback(func(pfs []astiav.PixelFormat) astiav.PixelFormat {
|
||||||
for _, pf := range pfs {
|
for _, pf := range pfs {
|
||||||
if pf == hardwarePixelFormat {
|
if pf == hardwarePixelFormat {
|
||||||
@@ -336,6 +336,17 @@ func initFilter() (err error) {
|
|||||||
inputs.SetPadIdx(0)
|
inputs.SetPadIdx(0)
|
||||||
inputs.SetNext(nil)
|
inputs.SetNext(nil)
|
||||||
|
|
||||||
|
// Loop through filters
|
||||||
|
for _, f := range filterGraph.Filters() {
|
||||||
|
// Filter doesn't handle hardware devices
|
||||||
|
if !f.Filter().Flags().Has(astiav.FilterFlagHardwareDevice) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update hardware device context
|
||||||
|
f.SetHardwareDeviceContext(hardwareDeviceContext)
|
||||||
|
}
|
||||||
|
|
||||||
// Parse
|
// Parse
|
||||||
if err = filterGraph.Parse(*filter, inputs, outputs); err != nil {
|
if err = filterGraph.Parse(*filter, inputs, outputs); err != nil {
|
||||||
err = fmt.Errorf("main: parsing filter failed: %w", err)
|
err = fmt.Errorf("main: parsing filter failed: %w", err)
|
||||||
|
Reference in New Issue
Block a user