@@ -152,14 +152,21 @@ export class StreamingService {
152152 await this . playVideo ( message , queueItem . url , queueItem . title , videoParams ) ;
153153 }
154154
155- private async getVideoParameters ( videoUrl : string ) : Promise < { width : number , height : number , fps ?: number , bitrate ?: string } | undefined > {
155+ private async getVideoParameters ( videoUrl : string ) : Promise < { width : number , height : number , fps ?: number , bitrate ?: number } | undefined > {
156156 try {
157157 const resolution = await getVideoParams ( videoUrl ) ;
158- logger . info ( `Video parameters: ${ resolution . width } x${ resolution . height } , FPS: ${ resolution . fps || 'unknown' } ` ) ;
158+ logger . info ( `Video parameters: ${ resolution . width } x${ resolution . height } , FPS: ${ resolution . fps || 'unknown' } , Bitrate: ${ resolution . bitrate || 'unknown' } ` ) ;
159+
160+ let bitrateKbps : number | undefined ;
161+ if ( resolution . bitrate ) {
162+ bitrateKbps = Math . round ( parseInt ( resolution . bitrate ) / 1000 ) ;
163+ }
164+
159165 return {
160166 width : resolution . width ,
161167 height : resolution . height ,
162- fps : resolution . fps
168+ fps : resolution . fps ,
169+ bitrate : bitrateKbps
163170 } ;
164171 } catch ( error ) {
165172 await ErrorUtils . handleError ( error , 'determining video parameters' ) ;
@@ -189,12 +196,38 @@ export class StreamingService {
189196 }
190197 }
191198
192- private setupStreamConfiguration ( videoParams ?: { width : number , height : number , fps ?: number , bitrate ?: string } ) : any {
199+ private setupStreamConfiguration ( videoParams ?: { width : number , height : number , fps ?: number , bitrate ?: number } ) : any {
200+ let width = videoParams ?. width || config . width ;
201+ let height = videoParams ?. height || config . height ;
202+ let frameRate = videoParams ?. fps || config . fps ;
203+ let bitrateVideo = config . bitrateKbps ;
204+
205+ // If respecting video params, use video bitrate unless overridden
206+ if ( videoParams && videoParams . bitrate && ! config . bitrateOverride ) {
207+ bitrateVideo = videoParams . bitrate ;
208+ }
209+
210+ // Resolution capping
211+ if ( config . maxWidth > 0 || config . maxHeight > 0 ) {
212+ const ratio = width / height ;
213+ if ( config . maxWidth > 0 && width > config . maxWidth ) {
214+ width = config . maxWidth ;
215+ height = Math . round ( width / ratio ) ;
216+ }
217+ if ( config . maxHeight > 0 && height > config . maxHeight ) {
218+ height = config . maxHeight ;
219+ width = Math . round ( height * ratio ) ;
220+ }
221+ // Ensure even dimensions
222+ width = Math . round ( width / 2 ) * 2 ;
223+ height = Math . round ( height / 2 ) * 2 ;
224+ }
225+
193226 return {
194- width : videoParams ?. width || config . width ,
195- height : videoParams ?. height || config . height ,
196- frameRate : videoParams ?. fps || config . fps ,
197- bitrateVideo : config . bitrateKbps ,
227+ width,
228+ height,
229+ frameRate,
230+ bitrateVideo,
198231 bitrateVideoMax : config . maxBitrateKbps ,
199232 videoCodec : Utils . normalizeVideoCodec ( config . videoCodec ) ,
200233 hardwareAcceleratedDecoding : config . hardwareAcceleratedDecoding ,
@@ -337,7 +370,7 @@ export class StreamingService {
337370 }
338371 }
339372
340- public async playVideo ( message : Message , videoSource : string , title ?: string , videoParams ?: { width : number , height : number , fps ?: number , bitrate ?: string } ) : Promise < void > {
373+ public async playVideo ( message : Message , videoSource : string , title ?: string , videoParams ?: { width : number , height : number , fps ?: number , bitrate ?: number } ) : Promise < void > {
341374 const [ guildId , channelId ] = [ config . guildId , config . videoChannelId ] ;
342375 this . streamStatus . manualStop = false ;
343376
0 commit comments