@@ -10,6 +10,7 @@ import (
10
10
"time"
11
11
12
12
// Packages
13
+ media "github.com/mutablelogic/go-media"
13
14
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
14
15
15
16
// Namespace imports
@@ -172,6 +173,30 @@ func (r *Reader) Duration() time.Duration {
172
173
return 0
173
174
}
174
175
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
+
175
200
// Return the metadata for the media stream, filtering by the specified keys
176
201
// if there are any. Artwork is returned with the "artwork" key.
177
202
func (r * Reader ) Metadata (keys ... string ) []* Metadata {
0 commit comments