Skip to content

Commit

Permalink
Added find output format
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Apr 14, 2024
1 parent 26ff0f1 commit 37b487d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions output_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package astiav
//#cgo pkg-config: libavformat
//#include <libavformat/avformat.h>
import "C"
import "unsafe"

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L503
type OutputFormat struct {
Expand All @@ -16,6 +17,25 @@ func newOutputFormatFromC(c *C.struct_AVOutputFormat) *OutputFormat {
return &OutputFormat{c: c}
}

func FindOutputFormat(name string) *OutputFormat {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return newOutputFormatFromC(C.av_guess_format(cname, nil, nil))
}

func (f *OutputFormat) Flags() IOFormatFlags {
return IOFormatFlags(f.c.flags)
}

func (f *OutputFormat) Name() string {
return C.GoString(f.c.name)
}

// LongName Description of the format, meant to be more human-readable than Name.
func (f *OutputFormat) LongName() string {
return C.GoString(f.c.long_name)
}

func (f *OutputFormat) String() string {
return f.Name()
}
16 changes: 16 additions & 0 deletions output_format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package astiav

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestOutputFormat(t *testing.T) {
formatName := "rawvideo"
outputFormat := FindOutputFormat(formatName)
require.NotNil(t, outputFormat)
require.Equal(t, formatName, outputFormat.Name())
require.Equal(t, formatName, outputFormat.String())
require.Equal(t, "raw video", outputFormat.LongName())
}

0 comments on commit 37b487d

Please sign in to comment.