subtitles_test.go
| 1 | package service |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // Index is an ffmpeg "0:s:N" selector. A bitmap track is unusable but still |
| 6 | // occupies a slot, so skipping it must not shift the following tracks. |
| 7 | func TestSelectSubtitleStreamsCountsSkippedTracks(t *testing.T) { |
| 8 | streams := []ffprobeStream{ |
| 9 | {CodecType: "video", CodecName: "h264"}, |
| 10 | {CodecType: "audio", CodecName: "aac"}, |
| 11 | {CodecType: "subtitle", CodecName: "hdmv_pgs_subtitle"}, |
| 12 | {CodecType: "subtitle", CodecName: "subrip"}, |
| 13 | {CodecType: "subtitle", CodecName: "ass"}, |
| 14 | } |
| 15 | streams[3].Tags.Language = "eng" |
| 16 | |
| 17 | got := selectSubtitleStreams(streams) |
| 18 | if len(got) != 2 { |
| 19 | t.Fatalf("got %d streams, want 2: %+v", len(got), got) |
| 20 | } |
| 21 | if got[0].Index != 1 || got[0].Lang != "eng" || got[0].Label != "ENG" { |
| 22 | t.Errorf("subrip track = %+v, want index 1 lang eng label ENG", got[0]) |
| 23 | } |
| 24 | // No language tag, so the name falls back to the selector index. |
| 25 | if got[1].Index != 2 || got[1].Lang != "track2" { |
| 26 | t.Errorf("ass track = %+v, want index 2 lang track2", got[1]) |
| 27 | } |
| 28 | } |
| 29 |