Fixed hardware filtering example

This commit is contained in:
Quentin Renard
2024-12-20 14:42:10 +01:00
parent 805ca1b8a1
commit 04ab7084e1
2 changed files with 7 additions and 2 deletions

View File

@@ -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())

View File

@@ -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)