Skip to content

Commit b61c969

Browse files
committed
Added BestStream
1 parent 931b733 commit b61c969

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pkg/ffmpeg/reader.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
// Packages
13+
media "github.com/mutablelogic/go-media"
1314
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
1415

1516
// Namespace imports
@@ -172,6 +173,30 @@ func (r *Reader) Duration() time.Duration {
172173
return 0
173174
}
174175

176+
// Return the "best stream" for a specific media type, or -1 if there is no
177+
// "best stream" for that type.
178+
func (r *Reader) BestStream(t media.Type) int {
179+
switch {
180+
case t.Is(media.VIDEO):
181+
if stream, _, err := ff.AVFormat_find_best_stream(r.input, ff.AVMEDIA_TYPE_VIDEO, -1, -1); err == nil {
182+
return r.input.Stream(stream).Id()
183+
}
184+
case t.Is(media.AUDIO):
185+
if stream, _, err := ff.AVFormat_find_best_stream(r.input, ff.AVMEDIA_TYPE_AUDIO, -1, -1); err == nil {
186+
return r.input.Stream(stream).Id()
187+
}
188+
case t.Is(media.SUBTITLE):
189+
if stream, _, err := ff.AVFormat_find_best_stream(r.input, ff.AVMEDIA_TYPE_SUBTITLE, -1, -1); err == nil {
190+
return r.input.Stream(stream).Id()
191+
}
192+
case t.Is(media.DATA):
193+
if stream, _, err := ff.AVFormat_find_best_stream(r.input, ff.AVMEDIA_TYPE_DATA, -1, -1); err == nil {
194+
return r.input.Stream(stream).Id()
195+
}
196+
}
197+
return -1
198+
}
199+
175200
// Return the metadata for the media stream, filtering by the specified keys
176201
// if there are any. Artwork is returned with the "artwork" key.
177202
func (r *Reader) Metadata(keys ...string) []*Metadata {

type.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ func (t Type) String() string {
3838
return "UNKNOWN"
3939
}
4040
}
41+
42+
///////////////////////////////////////////////////////////////////////////////
43+
// METHODS
44+
45+
func (t Type) Is(u Type) bool {
46+
// TODO: Change later to flags
47+
return t == u
48+
}

0 commit comments

Comments
 (0)