不廢話 直接上效果圖
C# winform 開發抖音的瀑布流字幕。
也是typemonkey插件字幕效果
或者咱再網上常說的倒鴨子字幕效果
主要功能
1,軟件可以自定義添加字幕內容
2,軟件可以添加字幕顯示的時間區間
3,可以自定義字幕顏色,可以隨機顏色
4,支持字幕的上下調節
5,支持字幕的刪除行和清空
6,支持字幕的導出和導入
7,支持上傳背景音樂mp3
8,支持更換背景顏色和背景圖片
9,支持導入srt字幕文件,也就是剪映導出的字幕文件,這樣能有效的把字幕和口播的音頻進行對齊。
10,可以自定義字幕的字體。
下面給大家展示一下功能圖片
// 定義內容文本數組,調整了每行字幕的持續時間let contentTexts = [{ "inPoint": 0, "outPoint": 1500, "content": "嘟", "color": "#FF0000", "fontFamily": "Microsoft YaHei"},{ "inPoint": 1500, "outPoint": 3000, "content": "您好", "color": "#33FF57", "fontFamily": "字由點字墩墩體"},{ "inPoint": 3000, "outPoint": 4500, "content": "您是大法師嗎?", "fontFamily": "抖音美好體"},{ "inPoint": 4500, "outPoint": 6000, "content": "哎", "color": "#3357FF", "fontFamily": "抖音美好體"},{ "inPoint": 6000, "outPoint": 7500, "content": "1212哎", "color": "#3357FF", "fontFamily": "Microsoft YaHei"},{ "inPoint": 7500, "outPoint": 9000, "content": "哎222222", "color": "#3357FF", "fontFamily": "抖音美好體"},{ "inPoint": 9000, "outPoint": 10500, "content": "哎3333333333", "color": "#3357FF", "fontFamily": "Microsoft YaHei"},{ "inPoint": 10500, "outPoint": 12000, "content": "3333哎", "color": "#3357FF", "fontFamily": "Arial"},{ "inPoint": 12000, "outPoint": 13500, "content": "22222222222222哎", "color": "#3357FF", "fontFamily": "抖音美好體"},{ "inPoint": 13500, "outPoint": 15000, "content": "哎", "color": "#3357FF", "fontFamily": "Arial"},{ "inPoint": 15000, "outPoint": 18000, "content": "111111111111111哎", "color": "#3357FF", "fontFamily": "Arial"},];
例如 導入srt文件的c# 代碼
?
private void ParseSRTFile(string filePath){string[] lines = File.ReadAllLines(filePath);dgv_lens.Rows.Clear(); // Clear existing rows// Temporary variables for SRT parsingstring currentContent = "";TimeSpan inPoint = TimeSpan.Zero;TimeSpan outPoint = TimeSpan.Zero;Random random = new Random();string[] colors = new string[]{"#5AAEF3", "#62D9AD", "#5B6E96", "#a8dffa", "#ffdc4c","#FF974C", "#E65A56", "#6D61E4", "#4A6FE2", "#6D9AE7","#23C2DB", "#D4EC59", "#FFE88E", "#FEB64D", "#FB6E6C"};// Parsing logicfor (int i = 0; i < lines.Length; i++){string line = lines[i].Trim();// Check for time codeif (line.Contains("-->")){// Split the time codesvar timeCodes = line.Split(new[] { " --> " }, StringSplitOptions.None);if (timeCodes.Length == 2){try{inPoint = TimeSpan.ParseExact(timeCodes[0].Trim(), @"hh\:mm\:ss\,fff", CultureInfo.InvariantCulture);outPoint = TimeSpan.ParseExact(timeCodes[1].Trim(), @"hh\:mm\:ss\,fff", CultureInfo.InvariantCulture);}catch (FormatException ex){MessageBox.Show($"Error parsing time codes: {ex.Message}", "Parsing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);return; }}}else if (!string.IsNullOrEmpty(line) && !line.All(char.IsDigit)){// This line is the contentcurrentContent = line;// Add the row to the DataGridViewint index = dgv_lens.Rows.Add();dgv_lens.Rows[index].Cells[0].Value = currentContent;dgv_lens.Rows[index].Cells[1].Value = cbRandomColor.Checked ? colors[random.Next(colors.Length)] : lbTextColor.Tag.ToString();dgv_lens.Rows[index].Cells[2].Value = (int)inPoint.TotalMilliseconds; // Convert TimeSpan to millisecondsdgv_lens.Rows[index].Cells[3].Value = (int)outPoint.TotalMilliseconds; // Convert TimeSpan to millisecondsdgv_lens.Rows[index].Cells[4].Value = cbFonts.Text; // Current font selection}}MessageBox.Show("SRT file imported successfully!", "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);}