|
| 1 | +package ffmpeg |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "fmt" |
| 6 | +) |
| 7 | + |
| 8 | +//////////////////////////////////////////////////////////////////////////////// |
| 9 | +// CGO |
| 10 | + |
| 11 | +/* |
| 12 | +#cgo pkg-config: libavfilter |
| 13 | +#include <libavfilter/avfilter.h> |
| 14 | +*/ |
| 15 | +import "C" |
| 16 | + |
| 17 | +//////////////////////////////////////////////////////////////////////////////// |
| 18 | +// TYPES |
| 19 | + |
| 20 | +type ( |
| 21 | + AVFilterContext C.AVFilterContext |
| 22 | + AVFilter C.AVFilter |
| 23 | + AVFilterFlag C.int |
| 24 | + AVFilterGraph C.AVFilterGraph |
| 25 | +) |
| 26 | + |
| 27 | +//////////////////////////////////////////////////////////////////////////////// |
| 28 | +// GLOBALS |
| 29 | + |
| 30 | +const ( |
| 31 | + AVFILTER_FLAG_NONE AVFilterFlag = 0 |
| 32 | + AVFILTER_FLAG_DYNAMIC_INPUTS AVFilterFlag = C.AVFILTER_FLAG_DYNAMIC_INPUTS |
| 33 | + AVFILTER_FLAG_DYNAMIC_OUTPUTS AVFilterFlag = C.AVFILTER_FLAG_DYNAMIC_OUTPUTS |
| 34 | + AVFILTER_FLAG_SLICE_THREADS AVFilterFlag = C.AVFILTER_FLAG_SLICE_THREADS |
| 35 | + AVFILTER_FLAG_METADATA_ONLY AVFilterFlag = C.AVFILTER_FLAG_METADATA_ONLY |
| 36 | + AVFILTER_FLAG_HWDEVICE AVFilterFlag = C.AVFILTER_FLAG_HWDEVICE |
| 37 | + AVFILTER_FLAG_SUPPORT_TIMELINE AVFilterFlag = C.AVFILTER_FLAG_SUPPORT_TIMELINE |
| 38 | + AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC AVFilterFlag = C.AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
| 39 | + AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL AVFilterFlag = C.AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL |
| 40 | + AVFILTER_FLAG_MAX = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL |
| 41 | +) |
| 42 | + |
| 43 | +//////////////////////////////////////////////////////////////////////////////// |
| 44 | +// STRINGIFY |
| 45 | + |
| 46 | +func (ctx *AVFilter) MarshalJSON() ([]byte, error) { |
| 47 | + type j struct { |
| 48 | + Name string `json:"name"` |
| 49 | + Description string `json:"description"` |
| 50 | + Flags AVFilterFlag `json:"flags,omitzero"` |
| 51 | + Inputs uint `json:"inputs,omitempty"` |
| 52 | + Outputs uint `json:"outputs,omitempty"` |
| 53 | + } |
| 54 | + if ctx == nil { |
| 55 | + return json.Marshal(nil) |
| 56 | + } |
| 57 | + return json.Marshal(j{ |
| 58 | + Name: ctx.Name(), |
| 59 | + Description: ctx.Description(), |
| 60 | + Flags: ctx.Flags(), |
| 61 | + Inputs: ctx.Inputs(), |
| 62 | + Outputs: ctx.Outputs(), |
| 63 | + }) |
| 64 | +} |
| 65 | + |
| 66 | +func (ctx *AVFilter) String() string { |
| 67 | + data, err := json.MarshalIndent(ctx, "", " ") |
| 68 | + if err != nil { |
| 69 | + return err.Error() |
| 70 | + } |
| 71 | + return string(data) |
| 72 | +} |
| 73 | + |
| 74 | +//////////////////////////////////////////////////////////////////////////////// |
| 75 | +// AVFilter |
| 76 | + |
| 77 | +func (c *AVFilter) Name() string { |
| 78 | + return C.GoString(c.name) |
| 79 | +} |
| 80 | + |
| 81 | +func (c *AVFilter) Description() string { |
| 82 | + return C.GoString(c.description) |
| 83 | +} |
| 84 | + |
| 85 | +func (c *AVFilter) Flags() AVFilterFlag { |
| 86 | + return AVFilterFlag(c.flags) |
| 87 | +} |
| 88 | + |
| 89 | +func (c *AVFilter) Inputs() uint { |
| 90 | + return AVFilter_inputs(c) |
| 91 | +} |
| 92 | + |
| 93 | +func (c *AVFilter) Outputs() uint { |
| 94 | + return AVFilter_outputs(c) |
| 95 | +} |
| 96 | + |
| 97 | +//////////////////////////////////////////////////////////////////////////////// |
| 98 | +// AVFilterFlag |
| 99 | + |
| 100 | +func (v AVFilterFlag) Is(f AVFilterFlag) bool { |
| 101 | + return v&f == f |
| 102 | +} |
| 103 | + |
| 104 | +func (v AVFilterFlag) String() string { |
| 105 | + if v == AVFILTER_FLAG_NONE { |
| 106 | + return v.FlagString() |
| 107 | + } |
| 108 | + str := "" |
| 109 | + for i := AVFilterFlag(C.int(1)); i <= AVFILTER_FLAG_MAX; i <<= 1 { |
| 110 | + if v&i == i { |
| 111 | + str += "|" + i.FlagString() |
| 112 | + } |
| 113 | + } |
| 114 | + return str[1:] |
| 115 | +} |
| 116 | + |
| 117 | +func (v AVFilterFlag) FlagString() string { |
| 118 | + switch v { |
| 119 | + case AVFILTER_FLAG_NONE: |
| 120 | + return "AVFILTER_FLAG_NONE" |
| 121 | + case AVFILTER_FLAG_DYNAMIC_INPUTS: |
| 122 | + return "AVFILTER_FLAG_DYNAMIC_INPUTS" |
| 123 | + case AVFILTER_FLAG_DYNAMIC_OUTPUTS: |
| 124 | + return "AVFILTER_FLAG_DYNAMIC_OUTPUTS" |
| 125 | + case AVFILTER_FLAG_SLICE_THREADS: |
| 126 | + return "AVFILTER_FLAG_SLICE_THREADS" |
| 127 | + case AVFILTER_FLAG_METADATA_ONLY: |
| 128 | + return "AVFILTER_FLAG_METADATA_ONLY" |
| 129 | + case AVFILTER_FLAG_HWDEVICE: |
| 130 | + return "AVFILTER_FLAG_HWDEVICE" |
| 131 | + case AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC: |
| 132 | + return "AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC" |
| 133 | + case AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL: |
| 134 | + return "AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL" |
| 135 | + default: |
| 136 | + return fmt.Sprintf("AVFilterFlag(0x%08X)", uint32(v)) |
| 137 | + } |
| 138 | +} |
0 commit comments