Skip to content

Commit 06a8ba7

Browse files
committed
feat(bsf): add support for bitstream filter operations
Add native bindings for libavcodec/bsf.h including: - AVBitStreamFilter and AVBSFContext structures - Bitstream filter list operations - Function bindings for filter initialization, packet processing and cleanup - Remove custom implementations in favor of generated bindings The changes enable proper handling of bitstream filters in the FFmpeg wrapper, allowing for packet transformation operations like H.264/H.265 annexB conversions.
1 parent 077c8d4 commit 06a8ba7

8 files changed

Lines changed: 861 additions & 48 deletions

File tree

callbacks.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ffmpeg
33
import "unsafe"
44

55
// #include <libavcodec/avcodec.h>
6+
// #include <libavcodec/bsf.h>
67
// #include <libavcodec/codec.h>
78
// #include <libavcodec/codec_desc.h>
89
// #include <libavcodec/codec_id.h>

constants.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ffmpeg
22

33
// #include <libavcodec/avcodec.h>
4+
// #include <libavcodec/bsf.h>
45
// #include <libavcodec/codec.h>
56
// #include <libavcodec/codec_desc.h>
67
// #include <libavcodec/codec_id.h>

custom.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@ import (
2323
"unsafe"
2424
)
2525

26-
// AVBitStreamFilter represents an FFmpeg bitstream filter.
27-
// This is a minimal wrapper for the C struct.
28-
type AVBitStreamFilter struct {
29-
ptr *C.AVBitStreamFilter
30-
}
31-
32-
// Name returns the bitstream filter's name.
33-
func (bsf *AVBitStreamFilter) Name() string {
34-
return C.GoString(bsf.ptr.name)
35-
}
36-
37-
// CodecIds returns the array of codec IDs supported by this filter.
38-
// Returns nil if the filter supports all codecs.
39-
func (bsf *AVBitStreamFilter) CodecIds() *AVCodecID {
40-
if bsf.ptr.codec_ids == nil {
41-
return nil
42-
}
43-
return (*AVCodecID)(unsafe.Pointer(bsf.ptr.codec_ids))
44-
}
45-
46-
// PrivClass returns the AVClass for private data options, or nil if none.
47-
func (bsf *AVBitStreamFilter) PrivClass() *AVClass {
48-
if bsf.ptr.priv_class == nil {
49-
return nil
50-
}
51-
return &AVClass{ptr: bsf.ptr.priv_class}
52-
}
53-
5426
// AVMuxerIterate iterates over all registered muxers.
5527
//
5628
// @param opaque a pointer where libavformat will store the iteration state. Must

enums.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ffmpeg
33
import "unsafe"
44

55
// #include <libavcodec/avcodec.h>
6+
// #include <libavcodec/bsf.h>
67
// #include <libavcodec/codec.h>
78
// #include <libavcodec/codec_desc.h>
89
// #include <libavcodec/codec_id.h>

examples/introspect/main.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func main() {
5757
func listCodecs() {
5858
fmt.Println("==================================================")
5959
fmt.Println("CODECS")
60-
fmt.Println("==================================================\n")
60+
fmt.Println("==================================================")
6161
fmt.Printf(" %s %-24s %-42s %s\n", "DE", "NAME", "DESCRIPTION", "TYPE")
6262
fmt.Println()
6363

@@ -198,7 +198,7 @@ func getCodecName(codecID ffmpeg.AVCodecID) string {
198198
func listFormats() {
199199
fmt.Println("\n==================================================")
200200
fmt.Println("FORMATS")
201-
fmt.Println("==================================================\n")
201+
fmt.Println("==================================================")
202202
fmt.Printf("%s %-24s %-42s %-35s %s\n", "DE", "NAME", "DESCRIPTION", "CODECS", "MIME TYPE")
203203
fmt.Println()
204204

@@ -413,7 +413,7 @@ func listFormats() {
413413
func listBSFs() {
414414
fmt.Println("\n==================================================")
415415
fmt.Println("BITSTREAM FILTERS")
416-
fmt.Println("==================================================\n")
416+
fmt.Println("==================================================")
417417
fmt.Printf(" %-24s %-42s\n", "NAME", "SUPPORTED CODECS")
418418
fmt.Println()
419419

@@ -429,11 +429,11 @@ func listBSFs() {
429429
count++
430430

431431
// Get the bitstream filter name
432-
name := bsf.Name()
432+
nameStr := bsf.Name().String()
433433

434434
// Truncate name if too long
435-
if len(name) > 24 {
436-
name = name[:24]
435+
if len(nameStr) > 24 {
436+
nameStr = nameStr[:24]
437437
}
438438

439439
// Get supported codec IDs
@@ -443,11 +443,11 @@ func listBSFs() {
443443
codecSpecificCount++
444444
var codecs []string
445445
for i := uintptr(0); ; i++ {
446-
codecID := (*ffmpeg.AVCodecID)(unsafe.Pointer(uintptr(unsafe.Pointer(codecIDs)) + i*unsafe.Sizeof(*codecIDs)))
447-
if *codecID == ffmpeg.AVCodecIdNone {
446+
codecID := codecIDs.Get(i)
447+
if codecID == ffmpeg.AVCodecIdNone {
448448
break
449449
}
450-
codecName := getCodecName(*codecID)
450+
codecName := getCodecName(codecID)
451451
codecs = append(codecs, codecName)
452452
}
453453
if len(codecs) > 0 {
@@ -458,7 +458,7 @@ func listBSFs() {
458458
}
459459
}
460460

461-
fmt.Printf(" %-24s %-42s\n", name, codecList)
461+
fmt.Printf(" %-24s %-42s\n", nameStr, codecList)
462462
}
463463

464464
fmt.Printf("\nSummary:\n")
@@ -470,7 +470,7 @@ func listBSFs() {
470470
func listParsers() {
471471
fmt.Println("\n==================================================")
472472
fmt.Println("PARSERS")
473-
fmt.Println("==================================================\n")
473+
fmt.Println("==================================================")
474474
fmt.Printf(" %-24s %-42s\n", "NAME", "SUPPORTED CODECS")
475475
fmt.Println()
476476

@@ -538,7 +538,7 @@ func listParsers() {
538538
func listProtocols() {
539539
fmt.Println("\n==================================================")
540540
fmt.Println("PROTOCOLS")
541-
fmt.Println("==================================================\n")
541+
fmt.Println("==================================================")
542542
fmt.Printf("%s %-24s\n", "IO", "NAME")
543543
fmt.Println()
544544

@@ -701,7 +701,7 @@ func getHWDeviceTypeFromCodec(codec *ffmpeg.AVCodec) ffmpeg.AVHWDeviceType {
701701
func listHWAccels() {
702702
fmt.Println("\n==================================================")
703703
fmt.Println("HARDWARE ACCELERATORS")
704-
fmt.Println("==================================================\n")
704+
fmt.Println("==================================================")
705705

706706
// First list hardware device types
707707
fmt.Printf(" %-24s\n", "NAME")
@@ -749,7 +749,7 @@ func listHWAccels() {
749749
// Unified list of hardware acceleration (hwaccels + hardware codecs)
750750
fmt.Println("\n==================================================")
751751
fmt.Println("HARDWARE CODECS")
752-
fmt.Println("==================================================\n")
752+
fmt.Println("==================================================")
753753
fmt.Printf(" %s %-24s %-42s %s %s\n", "DEH", "NAME", "DESCRIPTION", "TYPE", "PRESENT")
754754
fmt.Println()
755755

@@ -981,7 +981,7 @@ func listHWAccels() {
981981
func listFilters() {
982982
fmt.Println("\n==================================================")
983983
fmt.Println("FILTERS")
984-
fmt.Println("==================================================\n")
984+
fmt.Println("==================================================")
985985
fmt.Printf(" %s %-24s %-42s %s\n", "TSHM", "NAME", "DESCRIPTION", "TYPE")
986986
fmt.Println()
987987

@@ -1556,7 +1556,7 @@ func buildBSFMap() map[ffmpeg.AVCodecID][]string {
15561556
break
15571557
}
15581558

1559-
name := bsf.Name()
1559+
name := bsf.Name().String()
15601560
codecIDs := bsf.CodecIds()
15611561

15621562
if codecIDs == nil {
@@ -1565,11 +1565,11 @@ func buildBSFMap() map[ffmpeg.AVCodecID][]string {
15651565
} else {
15661566
// Codec-specific BSF
15671567
for i := uintptr(0); ; i++ {
1568-
codecID := (*ffmpeg.AVCodecID)(unsafe.Pointer(uintptr(unsafe.Pointer(codecIDs)) + i*unsafe.Sizeof(*codecIDs)))
1569-
if *codecID == ffmpeg.AVCodecIdNone {
1568+
codecID := codecIDs.Get(i)
1569+
if codecID == ffmpeg.AVCodecIdNone {
15701570
break
15711571
}
1572-
bsfMap[*codecID] = append(bsfMap[*codecID], name)
1572+
bsfMap[codecID] = append(bsfMap[codecID], name)
15731573
}
15741574
}
15751575
}

0 commit comments

Comments
 (0)