forked from CANKOLCAK/SmartRender
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoBirlestir.cs
More file actions
183 lines (166 loc) · 6.33 KB
/
VideoBirlestir.cs
File metadata and controls
183 lines (166 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SmartRender.Render;
using System.Diagnostics;
using SmartRender.MainClass;
using System.IO;
using System.Threading;
namespace SmartRender
{
public partial class VideoBirlestir : Form
{
int _index = 0;
string INTRO = string.Empty;
public VideoBirlestir()
{
InitializeComponent();
WorkList.Columns[0].Width = WorkList.Width - 105;
if(Language.ViewLanguage == Language.Languages.Turkish.ToString())
{
tDuration.Text = "Toplam Süre";
label1.Text = "Videonun Kayıt Edileceği Yer";
label2.Text = "Çıktı Dosyasının Adı";
ok.Text = "TAMAM";
change.Text = "Değiştir";
Text = "Video Birleştir";
comb.Text = "Video Birleştir";
}
else
{
tDuration.Text = "Total Duration";
label1.Text = "Output Folder";
label2.Text = "Output File Name";
ok.Text = "DONE";
change.Text = "Change";
Text = "Video Combine";
comb.Text = "Video Combine";
}
}
private void WorkList_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void WorkList_DragDrop(object sender, DragEventArgs e)
{
String[] videos = (String[])e.Data.GetData(DataFormats.FileDrop);
foreach(string video in videos)
{
Video._addF(video, WorkList);
}
}
public void Intro()
{
#region Create Initialize
using(StreamWriter sw= new StreamWriter("1.txt"))
{
string pros = WorkList.Items[_index].Text;
sw.WriteLine(string.Format("file '{0}'",INTRO) + Environment.NewLine);
sw.WriteLine(string.Format("file '{0}'",pros));
sw.Close();
}
#endregion
}
public void Intro_Completing(object sender, EventArgs e)
{
BeginInvoke(new Action(() => pBar.Value = pBar.Maximum));
SendMessage.Success(Messages.MSG_14[Language.ViewingLanguage], "Success");
}
public void Birlestir()
{
using (StreamWriter sw = new StreamWriter("1.txt"))
{
foreach(ListViewItem file in WorkList.Items)
{
sw.WriteLine(string.Format("file '{0}'", file.Text));
}
sw.Close();
}
ProcessStartInfo s = new ProcessStartInfo
{
RedirectStandardError = true,
UseShellExecute = false,
LoadUserProfile = true,
CreateNoWindow = true,
FileName = Variables.FFMPEG,
Arguments = string.Format(@"-f concat -i ""{0}"" -preset ultrafast -b 2500k ""{1}/{2}""", "1.txt", t1.Text, t2.Text)
};
Process p = new Process { StartInfo = s };
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(Apply_Completing);
if (p.Start())
{
p.Refresh();
StreamReader testReader = p.StandardError;
while (testReader.ReadLine() != null)
{
try
{
string satir = testReader.ReadLine().Substring(0, 6);
if (satir == "frame=")
{
int t_index = testReader.ReadLine().IndexOf("time=");
string saniye = testReader.ReadLine().Substring(t_index + 5, 8);
double seconds = TimeSpan.Parse(saniye).TotalSeconds;
double toplam = TimeSpan.Parse(total.Text).TotalSeconds;
double process = (seconds / toplam) * 100;
string normal = process.ToString().Substring(0, process.ToString().IndexOf(","));
Console.WriteLine("%{0}", normal);
if (int.Parse(normal) < pBar.Maximum)
{
BeginInvoke(new Action(() => pBar.Value = int.Parse(normal)));
}
Application.DoEvents();
}
}
catch (Exception ex)
{
}
}
}
else
{ Console.WriteLine("Error"); }
}
Thread thr;
private void purpleButton2_Click(object sender, EventArgs e)
{
if (Directory.Exists(t1.Text)) { thr = new Thread(Birlestir); thr.Start(); } else { SendMessage.Success(Messages.MSG_7[Language.ViewingLanguage], "Error"); }
}
public void Apply_Completing(object sender, EventArgs e)
{
BeginInvoke(new Action(() => pBar.Value = pBar.Maximum));
SendMessage.Success(Messages.MSG_14[Language.ViewingLanguage],"Success");
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (WorkList.Items.Count > 0)
{
int TotalDuration = 0;
foreach (ListViewItem Duration in WorkList.Items)
{
TotalDuration += (int)TimeSpan.Parse(Duration.SubItems[1].Text).TotalSeconds;
}
pBar.Maximum = TotalDuration;
total.Text = TimeSpan.FromSeconds(double.Parse(TotalDuration.ToString())).ToString();
}
}
catch { }
}
private void purpleButton1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fd = new FolderBrowserDialog();
if(fd.ShowDialog() == DialogResult.OK)
{
t1.Text = fd.SelectedPath;
}
}
}
}