public async Task RunAsync() { ChatRenderer downloader = new ChatRenderer(DownloadOptions); Progress <ProgressReport> progress = new Progress <ProgressReport>(); progress.ProgressChanged += Progress_ProgressChanged; Status = TwitchTaskStatus.Running; OnPropertyChanged("Status"); try { await downloader.RenderVideoAsync(progress, TokenSource.Token); if (TokenSource.IsCancellationRequested) { Status = TwitchTaskStatus.Cancelled; OnPropertyChanged("Status"); } else { Status = TwitchTaskStatus.Finished; OnPropertyChanged("Status"); } } catch { Status = TwitchTaskStatus.Failed; OnPropertyChanged("Status"); } }
private static void RenderChat(Options inputOptions) { ChatRenderOptions renderOptions = new ChatRenderOptions(); renderOptions.InputFile = inputOptions.InputFile; renderOptions.OutputFile = inputOptions.OutputFile; renderOptions.BackgroundColor = SKColor.Parse(inputOptions.BackgroundColor); renderOptions.MessageColor = SKColor.Parse(inputOptions.MessageColor); renderOptions.ChatHeight = inputOptions.ChatHeight; renderOptions.ChatWidth = inputOptions.ChatWidth; renderOptions.BttvEmotes = inputOptions.BttvEmotes; renderOptions.FfzEmotes = inputOptions.FfzEmotes; renderOptions.Outline = inputOptions.Outline; renderOptions.OutlineSize = inputOptions.OutlineSize; renderOptions.Font = inputOptions.Font; renderOptions.FontSize = inputOptions.FontSize; switch (inputOptions.MessageFontStyle.ToLower()) { case "normal": renderOptions.MessageFontStyle = SKFontStyle.Normal; break; case "bold": renderOptions.MessageFontStyle = SKFontStyle.Bold; break; case "italic": renderOptions.MessageFontStyle = SKFontStyle.Italic; break; } switch (inputOptions.UsernameFontStyle.ToLower()) { case "normal": renderOptions.UsernameFontStyle = SKFontStyle.Normal; break; case "bold": renderOptions.UsernameFontStyle = SKFontStyle.Bold; break; case "italic": renderOptions.UsernameFontStyle = SKFontStyle.Italic; break; } renderOptions.UpdateRate = inputOptions.UpdateRate; renderOptions.PaddingLeft = inputOptions.PaddingLeft; renderOptions.Framerate = inputOptions.Framerate; renderOptions.InputArgs = inputOptions.InputArgs; renderOptions.OutputArgs = inputOptions.OutputArgs; renderOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : inputOptions.FfmpegPath; ChatRenderer chatDownloader = new ChatRenderer(renderOptions); Progress <ProgressReport> progress = new Progress <ProgressReport>(); progress.ProgressChanged += Progress_ProgressChanged; chatDownloader.RenderVideoAsync(progress, new CancellationToken()).Wait(); }
private async void btnRender_Click(object sender, RoutedEventArgs e) { bool validInputs = ValidateInputs(); if (validInputs) { SaveFileDialog saveFileDialog = new SaveFileDialog(); string fileFormat = comboFormat.SelectedItem.ToString(); saveFileDialog.Filter = $"{fileFormat} Files | *.{fileFormat.ToLower()}"; saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = Path.GetFileNameWithoutExtension(textJson.Text) + "." + fileFormat.ToLower(); if (saveFileDialog.ShowDialog() == true) { SKColor backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B, colorBackground.SelectedColor.Value.A); SKColor messageColor = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B); SaveSettings(); ChatRenderOptions options = GetOptions(saveFileDialog.FileName); SetImage("Images/ppOverheat.gif", true); btnRender.IsEnabled = false; ChatRenderer currentRender = new ChatRenderer(options); Progress <ProgressReport> renderProgress = new Progress <ProgressReport>(OnProgressChanged); try { await currentRender.RenderVideoAsync(renderProgress, new CancellationToken()); statusMessage.Text = "Done"; SetImage("Images/ppHop.gif", true); } catch (Exception ex) { statusMessage.Text = "ERROR"; SetImage("Images/peepoSad.png", false); AppendLog("ERROR: " + ex.Message); } statusProgressBar.Value = 0; btnRender.IsEnabled = true; } } else { MessageBox.Show("Please double check your inputs are valid", "Unable to parse inputs", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void Update(PageChatRender pageChatRender) { try { this.Width = Int32.Parse(pageChatRender.textWidth.Text) + 10; this.Height = Int32.Parse(pageChatRender.textHeight.Text) + 38; imgPreview.Height = Int32.Parse(pageChatRender.textHeight.Text); imgPreview.Width = Int32.Parse(pageChatRender.textWidth.Text); PreviewData previewData = JsonConvert.DeserializeObject <PreviewData>(File.ReadAllText("preview_data.json")); BlockingCollection <TwitchCommentPreview> finalComments = new BlockingCollection <TwitchCommentPreview>(); SKBitmap previewBitmap = new SKBitmap((int)this.Width, (int)imgPreview.Height); SKColor backgroundColor = new SKColor(pageChatRender.colorBackground.SelectedColor.Value.R, pageChatRender.colorBackground.SelectedColor.Value.G, pageChatRender.colorBackground.SelectedColor.Value.B); SKColor messageColor = new SKColor(pageChatRender.colorFont.SelectedColor.Value.R, pageChatRender.colorFont.SelectedColor.Value.G, pageChatRender.colorFont.SelectedColor.Value.B); ChatRenderOptions renderOptions = new ChatRenderOptions() { InputFile = pageChatRender.textJson.Text, OutputFile = "", BackgroundColor = backgroundColor, ChatHeight = Int32.Parse(pageChatRender.textHeight.Text), ChatWidth = Int32.Parse(pageChatRender.textWidth.Text), BttvEmotes = (bool)pageChatRender.checkBTTV.IsChecked, FfzEmotes = (bool)pageChatRender.checkFFZ.IsChecked, Outline = (bool)pageChatRender.checkOutline.IsChecked, Font = (string)pageChatRender.comboFont.SelectedItem, FontSize = Double.Parse(pageChatRender.textFontSize.Text), UpdateRate = Double.Parse(pageChatRender.textUpdateTime.Text), Timestamp = (bool)pageChatRender.checkTimestamp.IsChecked, MessageColor = messageColor, Framerate = Int32.Parse(pageChatRender.textFramerate.Text), InputArgs = Settings.Default.FfmpegInputArgs, OutputArgs = Settings.Default.FfmpegOutputArgs, MessageFontStyle = SKFontStyle.Normal, UsernameFontStyle = SKFontStyle.Bold }; System.Drawing.Size canvasSize = new System.Drawing.Size(renderOptions.ChatWidth, renderOptions.SectionHeight); SKPaint nameFont = new SKPaint() { Typeface = SKTypeface.FromFamilyName(renderOptions.Font, renderOptions.UsernameFontStyle), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.FontSize, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High }; SKPaint messageFont = new SKPaint() { Typeface = SKTypeface.FromFamilyName(renderOptions.Font, renderOptions.MessageFontStyle), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.FontSize, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High, Color = renderOptions.MessageColor }; List <ThirdPartyEmote> thirdPartyEmotes = new List <ThirdPartyEmote>(); Dictionary <string, SKBitmap> chatEmotes = new Dictionary <string, SKBitmap>(); Dictionary <string, SKBitmap> emojiCache = new Dictionary <string, SKBitmap>(); using (SKCanvas previewCanvas = new SKCanvas(previewBitmap)) { previewCanvas.Clear(backgroundColor); foreach (PreviewEmote previewDataEmote in previewData.emotes) { byte[] imageBytes = Convert.FromBase64String(previewDataEmote.image); SKBitmap emoteBitmap = SKBitmap.Decode(imageBytes); SKCodec emoteCodec; using (MemoryStream ms = new MemoryStream(imageBytes)) emoteCodec = SKCodec.Create(ms); ThirdPartyEmote emote = new ThirdPartyEmote(new List <SKBitmap>() { emoteBitmap }, emoteCodec, previewDataEmote.name, ".png", "0", 1, imageBytes); thirdPartyEmotes.Add(emote); } foreach (PreviewComment previewComment in previewData.comments) { int default_x = 2; System.Drawing.Point drawPos = new System.Drawing.Point(default_x, 0); string userName = previewComment.name; SKColor userColor = new SKColor(Convert.ToByte(previewComment.color.Substring(0, 2), 16), Convert.ToByte(previewComment.color.Substring(2, 2), 16), Convert.ToByte(previewComment.color.Substring(4, 2), 16)); List <SKBitmap> imageList = new List <SKBitmap>(); SKBitmap sectionImage = new SKBitmap(canvasSize.Width, canvasSize.Height); List <GifEmote> currentGifEmotes = new List <GifEmote>(); List <SKBitmap> emoteList = new List <SKBitmap>(); List <CheerEmote> cheerEmotes = new List <CheerEmote>(); List <SKRect> emotePositionList = new List <SKRect>(); new SKCanvas(sectionImage).Clear(renderOptions.BackgroundColor); Comment comment = new Comment(); comment.message = new Message(); Fragment msg = new Fragment(); msg.text = previewComment.message; comment.message.fragments = new List <Fragment>(); comment.message.fragments.Add(msg); if (renderOptions.Timestamp) { sectionImage = ChatRenderer.DrawTimestamp(sectionImage, imageList, messageFont, renderOptions, comment, canvasSize, ref drawPos, ref default_x); } if (previewComment.badges != null) { sectionImage = DrawBadges(sectionImage, imageList, renderOptions, canvasSize, ref drawPos, previewComment); } sectionImage = ChatRenderer.DrawUsername(sectionImage, imageList, renderOptions, nameFont, userName, userColor, canvasSize, ref drawPos); sectionImage = ChatRenderer.DrawMessage(sectionImage, imageList, renderOptions, currentGifEmotes, messageFont, emojiCache, chatEmotes, thirdPartyEmotes, cheerEmotes, comment, canvasSize, ref drawPos, ref default_x, emoteList, emotePositionList); int finalHeight = 0; foreach (var img in imageList) { finalHeight += img.Height; } SKBitmap finalImage = new SKBitmap(canvasSize.Width, finalHeight); SKCanvas finalImageCanvas = new SKCanvas(finalImage); finalHeight = 0; foreach (var img in imageList) { finalImageCanvas.DrawBitmap(img, 0, finalHeight); finalHeight += img.Height; img.Dispose(); } finalComments.Add(new TwitchCommentPreview(finalImage, Double.Parse(comment.content_offset_seconds.ToString()), currentGifEmotes, emoteList, emotePositionList)); } int y = 0; int tempHeight = 0; foreach (TwitchCommentPreview twitchCommentPreview in finalComments) { tempHeight += twitchCommentPreview.section.Height; } SKBitmap tempBitmap = new SKBitmap((int)this.Width, tempHeight); using (SKCanvas tempCanvas = new SKCanvas(tempBitmap)) { foreach (TwitchCommentPreview twitchCommentPreview in finalComments) { tempCanvas.DrawBitmap(twitchCommentPreview.section, 0, y, imagePaint); for (int i = 0; i < twitchCommentPreview.normalEmotes.Count; i++) { SKRect refrenceRect = twitchCommentPreview.normalEmotesPositions[i]; tempCanvas.DrawBitmap(twitchCommentPreview.normalEmotes[i], new SKRect(refrenceRect.Left, refrenceRect.Top + y, refrenceRect.Right, refrenceRect.Bottom + y), imagePaint); } y += twitchCommentPreview.section.Height; } } previewCanvas.DrawBitmap(tempBitmap, 0, previewBitmap.Height - tempBitmap.Height); } using (var stream = new MemoryStream()) { SKImage.FromBitmap(previewBitmap).Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream); var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); imgPreview.Source = bitmap; } } catch { try { this.Width = 500; this.Height = 338; imgPreview.Width = 500; imgPreview.Height = 300; SKBitmap errorBitmap = new SKBitmap(500, 300); using (SKCanvas skCanvas = new SKCanvas(errorBitmap)) { skCanvas.DrawText("ERROR, UNABLE TO RENDER CHAT", 40, 150, new SKPaint() { Typeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold), TextSize = 18, IsAntialias = true, FilterQuality = SKFilterQuality.High }); SKBitmap peepo = SKBitmap.Decode(Application .GetResourceStream(new Uri("pack://application:,,,/Images/peepoSad.png")).Stream); skCanvas.DrawBitmap(peepo, 370, 132); } using (var stream = new MemoryStream()) { SKImage.FromBitmap(errorBitmap).Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream); var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); imgPreview.Source = bitmap; } } catch { } } }
private async void btnRender_Click(object sender, RoutedEventArgs e) { bool validInputs = ValidateInputs(); if (validInputs) { SaveFileDialog saveFileDialog = new SaveFileDialog(); string fileFormat = comboFormat.SelectedItem.ToString(); saveFileDialog.Filter = $"{fileFormat} Files | *.{fileFormat.ToLower()}"; saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = Path.GetFileNameWithoutExtension(textJson.Text) + "." + fileFormat.ToLower(); if (saveFileDialog.ShowDialog() == true) { SKColor backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B, colorBackground.SelectedColor.Value.A); SKColor messageColor = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B); SaveSettings(); ChatRenderOptions options = new ChatRenderOptions() { InputFile = textJson.Text, OutputFile = saveFileDialog.FileName, BackgroundColor = backgroundColor, ChatHeight = Int32.Parse(textHeight.Text), ChatWidth = Int32.Parse(textWidth.Text), BttvEmotes = (bool)checkBTTV.IsChecked, FfzEmotes = (bool)checkFFZ.IsChecked, Outline = (bool)checkOutline.IsChecked, Font = (string)comboFont.SelectedItem, FontSize = Double.Parse(textFontSize.Text), UpdateRate = Double.Parse(textUpdateTime.Text), Timestamp = (bool)checkTimestamp.IsChecked, MessageColor = messageColor, Framerate = Int32.Parse(textFramerate.Text), InputArgs = Settings.Default.FfmpegInputArgs, OutputArgs = Settings.Default.FfmpegOutputArgs, MessageFontStyle = SKFontStyle.Normal, UsernameFontStyle = SKFontStyle.Bold, GenerateMask = (bool)checkMask.IsChecked, OutlineSize = 4, FfmpegPath = "ffmpeg", TempFolder = Settings.Default.TempPath, SubMessages = (bool)checkSub.IsChecked }; options.PaddingLeft = (int)Math.Floor(2 * options.EmoteScale); SetImage("Images/ppOverheat.gif", true); btnRender.IsEnabled = false; ChatRenderer currentRender = new ChatRenderer(options); Progress <ProgressReport> renderProgress = new Progress <ProgressReport>(OnProgressChanged); try { await currentRender.RenderVideoAsync(renderProgress, new CancellationToken()); statusMessage.Text = "Done"; SetImage("Images/ppHop.gif", true); } catch (Exception ex) { statusMessage.Text = "ERROR"; SetImage("Images/peepoSad.png", false); AppendLog("ERROR: " + ex.Message); } statusProgressBar.Value = 0; btnRender.IsEnabled = true; } } else { MessageBox.Show("Please double check your inputs are valid", "Unable to parse inputs", MessageBoxButton.OK, MessageBoxImage.Error); } }
private static void RenderChat(Options inputOptions) { ChatRenderOptions renderOptions = new ChatRenderOptions(); renderOptions.InputFile = inputOptions.InputFile; renderOptions.OutputFile = inputOptions.OutputFile; renderOptions.BackgroundColor = SKColor.Parse(inputOptions.BackgroundColor); renderOptions.MessageColor = SKColor.Parse(inputOptions.MessageColor); renderOptions.ChatHeight = inputOptions.ChatHeight; renderOptions.ChatWidth = inputOptions.ChatWidth; renderOptions.BttvEmotes = inputOptions.BttvEmotes; renderOptions.FfzEmotes = inputOptions.FfzEmotes; renderOptions.Outline = inputOptions.Outline; renderOptions.OutlineSize = inputOptions.OutlineSize; renderOptions.Font = inputOptions.Font; renderOptions.FontSize = inputOptions.FontSize; switch (inputOptions.MessageFontStyle.ToLower()) { case "normal": renderOptions.MessageFontStyle = SKFontStyle.Normal; break; case "bold": renderOptions.MessageFontStyle = SKFontStyle.Bold; break; case "italic": renderOptions.MessageFontStyle = SKFontStyle.Italic; break; } switch (inputOptions.UsernameFontStyle.ToLower()) { case "normal": renderOptions.UsernameFontStyle = SKFontStyle.Normal; break; case "bold": renderOptions.UsernameFontStyle = SKFontStyle.Bold; break; case "italic": renderOptions.UsernameFontStyle = SKFontStyle.Italic; break; } renderOptions.UpdateRate = inputOptions.UpdateRate; renderOptions.PaddingLeft = inputOptions.PaddingLeft; renderOptions.Framerate = inputOptions.Framerate; renderOptions.GenerateMask = inputOptions.GenerateMask; renderOptions.InputArgs = inputOptions.InputArgs; renderOptions.OutputArgs = inputOptions.OutputArgs; renderOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : Path.GetFullPath(inputOptions.FfmpegPath); renderOptions.TempFolder = inputOptions.TempFolder; renderOptions.SubMessages = inputOptions.SubMessages; if (renderOptions.GenerateMask && renderOptions.BackgroundColor.Alpha == 255) { Console.WriteLine("[WARNING] - Generate mask option has been selected with an opaque background. You most likely want to set a transparent background with --background-color \"#00000000\""); } ChatRenderer chatDownloader = new ChatRenderer(renderOptions); Progress <ProgressReport> progress = new Progress <ProgressReport>(); progress.ProgressChanged += Progress_ProgressChanged; chatDownloader.RenderVideoAsync(progress, new CancellationToken()).Wait(); }
public ActionResult GetHomePage() { try { var currentUserID = 0l; var currentHomeID = 0l; var re = Request; var headers = re.Headers; if (headers.ContainsKey("CurrentUserID")) { currentUserID = long.Parse(headers.GetCommaSeparatedValues("CurrentUserID").FirstOrDefault()); } if (headers.ContainsKey("CurrentHomeID")) { currentHomeID = long.Parse(headers.GetCommaSeparatedValues("CurrentHomeID").FirstOrDefault()); } var messages = new BaseCRUDService(currentUserID).GetCollection <MessageDisplayViewModel>(x => x.HomeID == currentHomeID && x.CreatedByID != 0); var messagesResult = new ChatRenderer(currentUserID).BuildMessagesForChat(messages); var result = new HomePageDisplayModel() { Messages = messagesResult }; if (new BaseCRUDService(currentUserID).Any <HomeSettingPostViewModel>(x => x.HomeID == currentHomeID)) { var nextMonth = DateTime.Now.AddMonths(1).Month.ToString(); var thisMonth = DateTime.Now.Month.ToString(); var rentDueDate = string.Empty; var rentDueDateDay = new BaseCRUDService(currentUserID).GetEntity <HomeSettingPostViewModel>(x => x.HomeID == currentHomeID).RentDueDateDay; if (rentDueDateDay.ToString() != "0") { var dateString = $"{rentDueDateDay}/{nextMonth}/{DateTime.Now.Year.ToString()}"; if (DateTime.Parse(dateString).AddMonths(-1).Date > DateTime.Now.Date) { dateString = $"{rentDueDateDay}/{thisMonth}/{DateTime.Now.Year.ToString()}"; } rentDueDate = DateTime.Parse(dateString).ToLongDateString(); } result.RentDueDate = rentDueDate; } if (result != null) { return(Ok(result)); } else { return(NotFound()); } } catch (System.Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, $"{ex.Message}")); } }