-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mutablelogic/ffmpeg61
Added SDL video player spike
- Loading branch information
Showing
47 changed files
with
1,189 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
// Packages | ||
ff "github.com/mutablelogic/go-media/sys/ffmpeg61" | ||
) | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// TYPES | ||
|
||
type ( | ||
ChannelLayout ff.AVChannelLayout | ||
Channel ff.AVChannel | ||
) | ||
|
||
type jsonChannelLayout struct { | ||
Name string `json:"name"` | ||
NumChannels int `json:"num_channels"` | ||
Order string `json:"order"` | ||
Channels []*Channel `json:"channels"` | ||
} | ||
|
||
type jsonChannel struct { | ||
Index int `json:"index"` | ||
Name string `json:"name"` | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// LIFECYCLE | ||
|
||
func newChannelLayout(channellayout *ff.AVChannelLayout) *ChannelLayout { | ||
if !ff.AVUtil_channel_layout_check(channellayout) { | ||
return nil | ||
} | ||
return (*ChannelLayout)(channellayout) | ||
} | ||
|
||
func newChannel(channel ff.AVChannel) *Channel { | ||
if channel == ff.AV_CHAN_NONE { | ||
return nil | ||
} | ||
return (*Channel)(&channel) | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// STRINGIFY | ||
|
||
func (ch *ChannelLayout) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(&jsonChannelLayout{ | ||
Name: ch.Name(), | ||
NumChannels: ch.NumChannels(), | ||
Order: ch.Order(), | ||
Channels: ch.Channels(), | ||
}) | ||
} | ||
|
||
func (ch *Channel) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(&jsonChannel{ | ||
Name: ch.Name(), | ||
Description: ch.Description(), | ||
}) | ||
} | ||
|
||
func (ch *ChannelLayout) String() string { | ||
data, _ := json.MarshalIndent(ch, "", " ") | ||
return string(data) | ||
} | ||
|
||
func (ch *Channel) String() string { | ||
data, _ := json.MarshalIndent(ch, "", " ") | ||
return string(data) | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PROPERTIES - CHANNEL LAYOUT | ||
|
||
func (ch *ChannelLayout) Name() string { | ||
if desc, err := ff.AVUtil_channel_layout_describe((*ff.AVChannelLayout)(ch)); err != nil { | ||
return "" | ||
} else { | ||
return desc | ||
} | ||
} | ||
|
||
func (ch *ChannelLayout) NumChannels() int { | ||
return ff.AVUtil_get_channel_layout_nb_channels((*ff.AVChannelLayout)(ch)) | ||
} | ||
|
||
func (ch *ChannelLayout) Channels() []*Channel { | ||
var result []*Channel | ||
for i := 0; i < ch.NumChannels(); i++ { | ||
channel := ff.AVUtil_channel_layout_channel_from_index((*ff.AVChannelLayout)(ch), i) | ||
if channel != ff.AV_CHAN_NONE { | ||
result = append(result, newChannel(channel)) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
func (ch *ChannelLayout) Order() string { | ||
order := (*ff.AVChannelLayout)(ch).Order() | ||
switch order { | ||
case ff.AV_CHANNEL_ORDER_UNSPEC: | ||
return "unspecified" | ||
case ff.AV_CHANNEL_ORDER_NATIVE: | ||
return "native" | ||
case ff.AV_CHANNEL_ORDER_CUSTOM: | ||
return "custom" | ||
case ff.AV_CHANNEL_ORDER_AMBISONIC: | ||
return "ambisonic" | ||
} | ||
return order.String() | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PROPERTIES - CHANNEL | ||
|
||
func (ch *Channel) Name() string { | ||
if desc, err := ff.AVUtil_channel_name((ff.AVChannel)(*ch)); err != nil { | ||
return "unknown" | ||
} else { | ||
return desc | ||
} | ||
} | ||
|
||
func (ch *Channel) Description() string { | ||
if desc, err := ff.AVUtil_channel_description((ff.AVChannel)(*ch)); err != nil { | ||
return "" | ||
} else { | ||
return desc | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ffmpeg_test | ||
|
||
import ( | ||
"testing" | ||
|
||
// Packages | ||
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg" | ||
assert "github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_channellayout_001(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
manager, err := ffmpeg.NewManager() | ||
if !assert.NoError(err) { | ||
t.FailNow() | ||
} | ||
|
||
for _, format := range manager.ChannelLayouts() { | ||
t.Logf("%v", format) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"encoding/json" | ||
"sort" | ||
|
||
// Packages | ||
media "github.com/mutablelogic/go-media" | ||
ff "github.com/mutablelogic/go-media/sys/ffmpeg61" | ||
) | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// TYPES | ||
|
||
type Codec ff.AVCodec | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// LIFECYCLE | ||
|
||
func newCodec(codec *ff.AVCodec) *Codec { | ||
return (*Codec)(codec) | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// STRINGIFY | ||
|
||
func (codec *Codec) MarshalJSON() ([]byte, error) { | ||
return (*ff.AVCodec)(codec).MarshalJSON() | ||
} | ||
|
||
func (codec *Codec) String() string { | ||
data, _ := json.MarshalIndent((*ff.AVCodec)(codec), "", " ") | ||
return string(data) | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
// Return the type of codec | ||
func (codec *Codec) Type() media.Type { | ||
switch (*ff.AVCodec)(codec).Type() { | ||
case ff.AVMEDIA_TYPE_AUDIO: | ||
return media.AUDIO | ||
case ff.AVMEDIA_TYPE_VIDEO: | ||
return media.VIDEO | ||
case ff.AVMEDIA_TYPE_SUBTITLE: | ||
return media.SUBTITLE | ||
} | ||
return media.NONE | ||
} | ||
|
||
// The name the codec is referred to by | ||
func (codec *Codec) Name() string { | ||
return (*ff.AVCodec)(codec).Name() | ||
} | ||
|
||
// The description of the codec | ||
func (codec *Codec) Description() string { | ||
return (*ff.AVCodec)(codec).LongName() | ||
} | ||
|
||
// Pixel formats supported by the codec. This is only valid for video codecs. | ||
// The first pixel format is the default. | ||
func (codec *Codec) PixelFormats() []string { | ||
pixfmts := (*ff.AVCodec)(codec).PixelFormats() | ||
result := make([]string, len(pixfmts)) | ||
for i, pixfmt := range pixfmts { | ||
result[i] = ff.AVUtil_get_pix_fmt_name(pixfmt) | ||
} | ||
return result | ||
} | ||
|
||
// Sample formats supported by the codec. This is only valid for audio codecs. | ||
// The first sample format is the default. | ||
func (codec *Codec) SampleFormats() []string { | ||
samplefmts := (*ff.AVCodec)(codec).SampleFormats() | ||
result := make([]string, len(samplefmts)) | ||
for i, samplefmt := range samplefmts { | ||
result[i] = ff.AVUtil_get_sample_fmt_name(samplefmt) | ||
} | ||
return result | ||
} | ||
|
||
// Sample rates supported by the codec. This is only valid for audio codecs. | ||
// The first sample rate is the highest, sort the list in reverse order. | ||
func (codec *Codec) SampleRates() []int { | ||
samplerates := (*ff.AVCodec)(codec).SupportedSamplerates() | ||
sort.Sort(sort.Reverse(sort.IntSlice(samplerates))) | ||
return samplerates | ||
} | ||
|
||
// Channel layouts supported by the codec. This is only valid for audio codecs. | ||
func (codec *Codec) ChannelLayouts() []string { | ||
chlayouts := (*ff.AVCodec)(codec).ChannelLayouts() | ||
result := make([]string, 0, len(chlayouts)) | ||
for _, chlayout := range chlayouts { | ||
name, err := ff.AVUtil_channel_layout_describe(&chlayout) | ||
if err != nil { | ||
continue | ||
} | ||
result = append(result, name) | ||
} | ||
return result | ||
} | ||
|
||
// Profiles supported by the codec. This is only valid for video codecs. | ||
func (codec *Codec) Profiles() []string { | ||
profiles := (*ff.AVCodec)(codec).Profiles() | ||
result := make([]string, len(profiles)) | ||
for i, profile := range profiles { | ||
result[i] = profile.Name() | ||
} | ||
return result | ||
} |
Oops, something went wrong.