Make sure max is at end

monorepo
Varun Patil 2022-12-01 13:05:19 -08:00
parent c57fb1ca56
commit 758812c699
2 changed files with 10 additions and 2 deletions

View File

@ -76,6 +76,8 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager,
// Only keep streams that are smaller than the video // Only keep streams that are smaller than the video
for k, stream := range m.streams { for k, stream := range m.streams {
stream.order = 0
// scale bitrate by frame rate with reference 30 // scale bitrate by frame rate with reference 30
stream.bitrate = int(float64(stream.bitrate) * float64(m.probe.FrameRate) / 30.0) stream.bitrate = int(float64(stream.bitrate) * float64(m.probe.FrameRate) / 30.0)
@ -94,8 +96,12 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager,
// Original stream // Original stream
m.streams["max"] = &Stream{ m.streams["max"] = &Stream{
c: c, m: m, quality: "max", height: m.probe.Height, width: m.probe.Width, c: c, m: m,
quality: "max",
height: m.probe.Height,
width: m.probe.Width,
bitrate: m.probe.BitRate, bitrate: m.probe.BitRate,
order: 1,
} }
// Start all streams // Start all streams
@ -213,7 +219,8 @@ func (m *Manager) ServeIndex(w http.ResponseWriter) error {
streams = append(streams, stream) streams = append(streams, stream)
} }
sort.Slice(streams, func(i, j int) bool { sort.Slice(streams, func(i, j int) bool {
return streams[i].bitrate < streams[j].bitrate return streams[i].order < streams[j].order ||
(streams[i].order == streams[j].order && streams[i].bitrate < streams[j].bitrate)
}) })
// Write all streams // Write all streams

View File

@ -33,6 +33,7 @@ type Stream struct {
c *Config c *Config
m *Manager m *Manager
quality string quality string
order int
height int height int
width int width int
bitrate int bitrate int