From 04ab7084e132b73bc29d3515f9bcba35a88e6dbc Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Fri, 20 Dec 2024 14:42:10 +0100 Subject: [PATCH] Fixed hardware filtering example --- examples/hardware_decoding_filtering/main.go | 4 ++-- frame.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/hardware_decoding_filtering/main.go b/examples/hardware_decoding_filtering/main.go index 65ffe02..0d3fade 100644 --- a/examples/hardware_decoding_filtering/main.go +++ b/examples/hardware_decoding_filtering/main.go @@ -228,7 +228,7 @@ func main() { // Make sure the filter is initialized // We need to wait for the first frame to be decoded before initializing the filter - // since the decoder codec context doesn't have a valid hardware frame context until then + // since we need a valid hardware frames context if filterGraph == nil { if err := initFilter(); err != nil { log.Fatal(fmt.Errorf("main: initializing filter failed: %w", err)) @@ -305,7 +305,7 @@ func initFilter() (err error) { // Create buffersrc context parameters buffersrcContextParameters := astiav.AllocBuffersrcFilterContextParameters() defer buffersrcContextParameters.Free() - buffersrcContextParameters.SetHardwareFramesContext(decCodecContext.HardwareFramesContext()) + buffersrcContextParameters.SetHardwareFramesContext(decodedHardwareFrame.HardwareFramesContext()) buffersrcContextParameters.SetHeight(decCodecContext.Height()) buffersrcContextParameters.SetPixelFormat(decCodecContext.PixelFormat()) buffersrcContextParameters.SetSampleAspectRatio(decCodecContext.SampleAspectRatio()) diff --git a/frame.go b/frame.go index f13d94e..dc3936c 100644 --- a/frame.go +++ b/frame.go @@ -87,6 +87,11 @@ func (f *Frame) Data() *FrameData { return newFrameData(newFrameDataFrame(f)) } +// https://ffmpeg.org/doxygen/7.0/structAVFrame.html#a29493fbfabaa21432c360a090426aa8e +func (f *Frame) HardwareFramesContext() *HardwareFramesContext { + return newHardwareFramesContextFromC(f.c.hw_frames_ctx) +} + // https://ffmpeg.org/doxygen/7.0/structAVFrame.html#a3f89733f429c98ba5bc64373fb0a3f13 func (f *Frame) Height() int { return int(f.c.height)