mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.4 KiB
33 lines
1.4 KiB
namespace ErsatzTV.FFmpeg.Filter; |
|
|
|
public class SongProgressFilter(FrameSize frameSize, Option<TimeSpan> maybeStart, Option<TimeSpan> maybeDuration) : BaseFilter |
|
{ |
|
public override string Filter |
|
{ |
|
get |
|
{ |
|
foreach (TimeSpan duration in maybeDuration) |
|
{ |
|
TimeSpan start = maybeStart.IfNone(TimeSpan.Zero); |
|
TimeSpan finish = start + duration; |
|
|
|
double width = frameSize.Width * 0.9; |
|
double height = frameSize.Height * 0.025; |
|
double seconds = duration.TotalSeconds; |
|
double alreadyPlayed = start.TotalSeconds / finish.TotalSeconds; |
|
double scale = 1 - alreadyPlayed; |
|
|
|
var generateGrayBar = $"color=c=#323232:s={width}x{height},format=rgba,colorchannelmixer=aa=0.4"; |
|
var generateWhiteBar = $"color=c=white:s={width}x{height}"; |
|
var scaleToFullWidth = $"scale=iw*{alreadyPlayed}+iw*(t/{seconds})*{scale}:ih:eval=frame"; |
|
var overlayBar = "overlay=W*0.05:H-h-H*0.05:shortest=1:enable='gt(t,0.1)'"; |
|
|
|
return $"loop=-1:1[si],{generateGrayBar}[gray];{generateWhiteBar},format=rgba,colorchannelmixer=aa=0.9,{scaleToFullWidth}[sbar];[si][gray]{overlayBar}[sgray];[sgray][sbar]{overlayBar}"; |
|
} |
|
|
|
return string.Empty; |
|
} |
|
} |
|
|
|
public override FrameState NextState(FrameState currentState) => currentState; |
|
}
|
|
|