Skip to content

Commit

Permalink
Add font color and bitrate options
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Nov 2, 2019
1 parent ec40f4e commit 6c8da9e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 9 deletions.
12 changes: 12 additions & 0 deletions TwitchDownloaderWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
<setting name="BackgroundColorB" serializeAs="String">
<value>17</value>
</setting>
<setting name="Bitrate" serializeAs="String">
<value>4000</value>
</setting>
<setting name="FontColorR" serializeAs="String">
<value>255</value>
</setting>
<setting name="FontColorG" serializeAs="String">
<value>255</value>
</setting>
<setting name="FontColorB" serializeAs="String">
<value>255</value>
</setting>
</TwitchDownloader.Properties.Settings>
</userSettings>
</configuration>
11 changes: 7 additions & 4 deletions TwitchDownloaderWPF/PageChatRender.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
<StackPanel Orientation="Vertical" Margin="0,0,5,0">
<TextBlock Text="Font:" HorizontalAlignment="Right" Margin="0,2,0,0"/>
<TextBlock Text="Font Size:" HorizontalAlignment="Right" Margin="0,14,0,0"/>
<TextBlock Text="Font Color:" HorizontalAlignment="Right" Margin="0,14,0,0"/>
<TextBlock Text="Bitrate (kbps):" HorizontalAlignment="Right" Margin="0,12,0,0"/>
<TextBlock Text="Outline:" HorizontalAlignment="Right" Margin="0,8,0,0"/>
<TextBlock Text="Timestamp:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="Compact Messages:" HorizontalAlignment="Right" Margin="0,5,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ComboBox x:Name="comboFont" MinWidth="150"/>
<TextBox x:Name="textFontSize" Text="12" Width="40" HorizontalAlignment="Left" Margin="0,5,0,0"/>
<ComboBox x:Name="comboFont" MinWidth="100"/>
<TextBox x:Name="textFontSize" Text="12" Width="40" HorizontalAlignment="Left" Margin="0,7,0,0"/>
<xctk:ColorPicker x:Name="colorFont" SelectedColor="#111111" Width="50" UsingAlphaChannel="False" Margin="0,5,0,0" HorizontalAlignment="Left"/>
<TextBox x:Name="textBitrate" Text="4000" Width="50" Margin="0,5,0,0" HorizontalAlignment="Left"/>
<CheckBox x:Name="checkOutline" Margin="0,5,0,0"/>
<CheckBox x:Name="checkTimestamp" Margin="0,5,0,0"/>
<CheckBox x:Name="checkCompact" Margin="0,5,0,0"/>
Expand All @@ -57,7 +61,6 @@
<TextBox x:Name="textUpdateTime" Text="1.0" Margin="0,5,0,0"/>
<CheckBox x:Name="checkFFZ" IsChecked="True" Margin="0,5,0,0"/>
<CheckBox x:Name="checkBTTV" IsChecked="True" Margin="0,5,0,0"/>

</StackPanel>
</StackPanel>

Expand All @@ -66,7 +69,7 @@
<TextBox x:Name="textJson" Margin="3" MinWidth="200" MaxWidth="400"/>
<Button x:Name="btnBrowse" Margin="3" MinWidth="50" Content="Browse" Click="btnBrowse_Click"/>
</WrapPanel>
<Button x:Name="btnRender" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="Render Chat" Height="50" Width="100" VerticalAlignment="Bottom" Margin="0,0,0,20" Click="btnRender_Click"/>
<Button x:Name="btnRender" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="Render Chat" Height="50" Width="100" VerticalAlignment="Bottom" Margin="0,0,0,10" Click="btnRender_Click"/>
<!-- RIGHT -->
<StackPanel Grid.Column="4" Grid.Row="2" Grid.RowSpan="2">
<TextBlock Text="Log:"/>
Expand Down
23 changes: 18 additions & 5 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ private void btnRender_Click(object sender, RoutedEventArgs e)
if (saveFileDialog.ShowDialog() == true)
{
SKColor backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B);
SKColor messageColor = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B);
System.Drawing.Color backgroundColorDrawing = System.Drawing.Color.FromArgb((int)colorBackground.SelectedColor.Value.R, (int)colorBackground.SelectedColor.Value.G, (int)colorBackground.SelectedColor.Value.B);
RenderOptions info = new RenderOptions(textJson.Text, saveFileDialog.FileName, backgroundColor, Int32.Parse(textHeight.Text), Int32.Parse(textWidth.Text), (bool)checkBTTV.IsChecked, (bool)checkFFZ.IsChecked, (bool)checkOutline.IsChecked, (string)comboFont.SelectedItem, Double.Parse(textFontSize.Text), Double.Parse(textUpdateTime.Text), (bool)checkCompact.IsChecked, backgroundColorDrawing, (bool)checkTimestamp.IsChecked);
RenderOptions info = new RenderOptions(textJson.Text, saveFileDialog.FileName, backgroundColor, Int32.Parse(textHeight.Text), Int32.Parse(textWidth.Text), (bool)checkBTTV.IsChecked, (bool)checkFFZ.IsChecked, (bool)checkOutline.IsChecked, (string)comboFont.SelectedItem, Double.Parse(textFontSize.Text), Double.Parse(textUpdateTime.Text), (bool)checkCompact.IsChecked, backgroundColorDrawing, (bool)checkTimestamp.IsChecked, messageColor, Int32.Parse(textBitrate.Text));
SaveSettings();
BackgroundWorker backgroundRenderManager = new BackgroundWorker();
backgroundRenderManager.WorkerReportsProgress = true;
Expand Down Expand Up @@ -129,7 +130,7 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)

Size canvasSize = new Size(renderOptions.chat_width, renderOptions.has_emote_height);
SKPaint nameFont = new SKPaint() { Typeface = SKTypeface.FromFamilyName(renderOptions.font, SKFontStyle.Bold), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.font_size, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High };
SKPaint messageFont = new SKPaint() { Typeface = SKTypeface.FromFamilyName(renderOptions.font, SKFontStyle.Normal), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.font_size, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High, Color = SKColors.White };
SKPaint messageFont = new SKPaint() { Typeface = SKTypeface.FromFamilyName(renderOptions.font, SKFontStyle.Normal), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.font_size, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High, Color = renderOptions.message_color };

(sender as BackgroundWorker).ReportProgress(0, new Progress("Rendering Comments"));
foreach (Comment comment in chatJson.comments)
Expand Down Expand Up @@ -253,7 +254,7 @@ private void RenderVideo(RenderOptions renderOptions, List<TwitchComment> finalC
{
// create new video file
stopwatch.Start();
vFWriter.Open(renderOptions.save_path, renderOptions.chat_width, renderOptions.chat_height, 60, VideoCodec.H264, 6000000);
vFWriter.Open(renderOptions.save_path, renderOptions.chat_width, renderOptions.chat_height, 60, VideoCodec.H264, renderOptions.bitrate * 1000);
gcan.FillRectangle(new System.Drawing.SolidBrush(backgroundColor), 0, 0, renderOptions.chat_width, renderOptions.chat_height);
int startTick = (int)Math.Floor(videoStart / (1.0 / 60.0));
int endTick = (int)Math.Floor((videoStart + duration) / (1.0 / 60.0));
Expand Down Expand Up @@ -460,7 +461,7 @@ private SKBitmap DrawMessage(SKBitmap sectionImage, List<SKBitmap> imageList, Re
if (messageBuffer != "")
sectionImage = DrawText(sectionImage, messageBuffer, messageFont, imageList, ref hasEmote, renderOptions, currentGifEmotes, canvasSize, ref drawPos, true, default_x);
SKPaint fallbackFont = GetFallbackFont(charList[j], renderOptions);
fallbackFont.Color = SKColors.White;
fallbackFont.Color = renderOptions.message_color;
sectionImage = DrawText(sectionImage, charList[j].ToString(), fallbackFont, imageList, ref hasEmote, renderOptions, currentGifEmotes, canvasSize, ref drawPos, false, default_x);
messageBuffer = "";
}
Expand Down Expand Up @@ -997,6 +998,8 @@ private void LoadSettings()
textWidth.Text = Settings.Default.Width.ToString();
textFontSize.Text = Settings.Default.FontSize.ToString();
textUpdateTime.Text = Settings.Default.UpdateTime.ToString();
colorFont.SelectedColor = System.Windows.Media.Color.FromRgb((byte)Settings.Default.FontColorR, (byte)Settings.Default.FontColorG, (byte)Settings.Default.FontColorB);
textBitrate.Text = Settings.Default.Bitrate.ToString();
}
catch { }
}
Expand All @@ -1011,8 +1014,13 @@ private void SaveSettings()
Settings.Default.BackgroundColorB = colorBackground.SelectedColor.Value.B;
Settings.Default.FFZEmotes = (bool)checkFFZ.IsChecked;
Settings.Default.BTTVEmotes = (bool)checkBTTV.IsChecked;
Settings.Default.FontColorR = colorFont.SelectedColor.Value.R;
Settings.Default.FontColorG = colorFont.SelectedColor.Value.G;
Settings.Default.FontColorB = colorFont.SelectedColor.Value.B;

try
{
Settings.Default.Bitrate = Int32.Parse(textBitrate.Text);
Settings.Default.Height = Int32.Parse(textHeight.Text);
Settings.Default.Width = Int32.Parse(textWidth.Text);
Settings.Default.FontSize = float.Parse(textFontSize.Text);
Expand All @@ -1036,6 +1044,7 @@ private bool ValidateInputs()
Int32.Parse(textHeight.Text);
Int32.Parse(textWidth.Text);
Double.Parse(textUpdateTime.Text);
Int32.Parse(textBitrate.Text);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1140,8 +1149,10 @@ public class RenderOptions
public string json_path { get; set; }
public string save_path { get; set; }
public SKColor background_color { get; set; }
public SKColor message_color { get; set; }
public int chat_height { get; set; }
public int chat_width { get; set; }
public int bitrate { get; set; }
public bool bttv_emotes { get; set; }
public bool ffz_emotes { get; set; }
public bool outline { get; set; }
Expand All @@ -1157,7 +1168,7 @@ public class RenderOptions
public bool chat_timestamp { get; set; }
public int default_x { get; set; }

public RenderOptions(string Json_path, string Save_path, SKColor Background_color, int Chat_height, int Chat_width, bool Bttv_emotes, bool Ffz_emotes, bool Outline, string Font, double Font_size, double Update_rate, bool Compact_messages, System.Drawing.Color Background_color_drawing, bool Chat_timestamp)
public RenderOptions(string Json_path, string Save_path, SKColor Background_color, int Chat_height, int Chat_width, bool Bttv_emotes, bool Ffz_emotes, bool Outline, string Font, double Font_size, double Update_rate, bool Compact_messages, System.Drawing.Color Background_color_drawing, bool Chat_timestamp, SKColor Message_color, int Bitrate)
{
json_path = Json_path;
save_path = Save_path;
Expand All @@ -1170,6 +1181,8 @@ public RenderOptions(string Json_path, string Save_path, SKColor Background_colo
font = Font;
font_size = Font_size;
image_scale = font_size / 12;
message_color = Message_color;
bitrate = Bitrate;

if (Update_rate == 0)
update_frame = 1;
Expand Down
48 changes: 48 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,17 @@
<Setting Name="BackgroundColorB" Type="System.Int32" Scope="User">
<Value Profile="(Default)">17</Value>
</Setting>
<Setting Name="Bitrate" Type="System.Int32" Scope="User">
<Value Profile="(Default)">4000</Value>
</Setting>
<Setting Name="FontColorR" Type="System.Int32" Scope="User">
<Value Profile="(Default)">255</Value>
</Setting>
<Setting Name="FontColorG" Type="System.Int32" Scope="User">
<Value Profile="(Default)">255</Value>
</Setting>
<Setting Name="FontColorB" Type="System.Int32" Scope="User">
<Value Profile="(Default)">255</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 6c8da9e

Please sign in to comment.