This repository was archived by the owner on Jun 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVidLapsPro.cs
More file actions
316 lines (279 loc) · 9.94 KB
/
VidLapsPro.cs
File metadata and controls
316 lines (279 loc) · 9.94 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#if PRO
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using UnityEngine;
using Google.YouTube;
using Google.GData.YouTube;
using Google.GData.Client;
using Google.GData.Extensions;
namespace VidLapse {
public partial class VidLapse : MonoBehaviour {
/**
* The name of the finished video
* @note Pro and Developer Version only
* @private
*/
private string _videoname="";
/**
* The application's youtube developer key
* @note Pro and Developer Version only
* @private
*/
private const string _youtubekey = "";
/**
* VidLapse Constructor
* @param freq The frequency to collect screenshots
* @param folder The folder to store images in the applications directory
* @note Pro and Developer Version only
*/
public VidLapse(float freq, string folder){
_frequency=freq;
_directory=folder;
_fullpath=Application.persistentDataPath+"/"+_directory;
}
/**
* VidLapse Constructor
* @param folder The folder to store images in the applications directory
* @note Pro and Developer Version only
*/
public VidLapse(string folder){
_frequency=1f;
_directory=folder;
_fullpath=Application.persistentDataPath+"/"+_directory;
}
/**
* VidLapse Constructor
* @param freq The frequency to collect screenshots
* @param fullpath The fullpath to output the captured screenshots
* @note Pro and Developer Version only
*/
public VidLapse(int freq, string fullpath){
_frequency=(float)freq;
_fullpath=fullpath;
_fullpathset=true;
}
/**
* VidLapse Constructor
* @param fullpath The fullpath to output the finished video
* @param blank Not used
* @note Pro and Developer Version only
*/
public VidLapse(string fullpath,bool blank){
_frequency=1f;
_fullpath=fullpath;
_fullpathset=true;
}
/**
* Upload the finished movie to YouTube
* @param user The username to use
* @param pass The password to use
* @return void
* @note Pro and Developer Version only
*/
public void Upload(string user, string pass){
YouTubeRequestSettings settings = new YouTubeRequestSettings("VidLapse",_youtubekey,user,pass);
YouTubeRequest request = new YouTubeRequest(settings);
Video vid = new Video();
vid.Title = _videoname;
vid.Description = "";
vid.YouTubeEntry.Private=false;
if(SaveToDesktop)
vid.YouTubeEntry.MediaSource = new MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"/"+_Filename+".avi","video/avi");
else
vid.YouTubeEntry.MediaSource = new MediaFileSource(_fullpath+"/"+_Filename+".avi","video/avi");
Video complete = request.Upload(vid);
}
/**
* Upload the finished movie to YouTube
* @param user The username to use
* @param pass The password to use
* @param videotitle The video title to use
* @return void
* @note Pro and Developer Version only
*/
public void Upload(string user, string pass,string videotitle){
YouTubeRequestSettings settings = new YouTubeRequestSettings("VidLapse",_youtubekey,user,pass);
YouTubeRequest request = new YouTubeRequest(settings);
Video vid = new Video();
vid.Title = videotitle;
vid.Description = "";
vid.YouTubeEntry.Private=false;
if(SaveToDesktop)
vid.YouTubeEntry.MediaSource = new MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"/"+_Filename+".avi","video/avi");
else
vid.YouTubeEntry.MediaSource = new MediaFileSource(_fullpath+"/"+_Filename+".avi","video/avi");
Video complete = request.Upload(vid);
}
/**
* Upload the finished movie to YouTube
* @param user The username to use
* @param pass The password to use
* @param videotitle The video title to use
* @param description The description to use
* @return void
* @note Pro and Developer Version only
*/
public void Upload(string user, string pass,string videotitle,string description){
YouTubeRequestSettings settings = new YouTubeRequestSettings("VidLapse",_youtubekey,user,pass);
YouTubeRequest request = new YouTubeRequest(settings);
Video vid = new Video();
vid.Title = videotitle;
vid.Description = description;
vid.YouTubeEntry.Private=false;
if(SaveToDesktop)
vid.YouTubeEntry.MediaSource = new MediaFileSource(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"/"+_Filename+".avi","video/avi");
else
vid.YouTubeEntry.MediaSource = new MediaFileSource(_fullpath+"/"+_Filename+".avi","video/avi");
Video complete = request.Upload(vid);
}
/**
* Create a movie from the captured shots
* @param width The width of the final movie
* @param height The height of the final movie
* @param framerate The framerate of the final movie
* @return void
* @note Pro and Developer Version only
*/
public void CreateMovie(int width, int height, int framerate){
if(_Filename==""){
_Filename="VidLapse-Video"+DateTime.Now.Millisecond+DateTime.Now.Second;
}
Bitmap bmp;
AviWriter aviw = new AviWriter();
if(SaveToDesktop){
bmp = aviw.Open(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"/"+_Filename+".avi",(uint)framerate,width,height);
}else{
bmp = aviw.Open(_fullpath+"/"+_Filename+".avi",(uint)framerate,width,height);
}
System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(bmp);
if (_saveMethod == SaveMethod.Disk) {
DirectoryInfo d = new DirectoryInfo(Application.persistentDataPath + "/");
FileInfo[] files = d.GetFiles("*.png");
foreach (FileInfo file in files) {
Bitmap bmp2 = new Bitmap(file.FullName);
bmp2.RotateFlip(RotateFlipType.Rotate180FlipX);
bmp2 = ReduceBitmap(bmp2, width, height);
canvas.Clear(System.Drawing.Color.White);
canvas.DrawImage(bmp2, 0, 0);
aviw.AddFrame();
}
} else {
for (int i = 0; i < _imageBytes.Count; i++) {
byte[] imgbytes = _imageBytes.Dequeue();
Bitmap bmp2 = ToBitmap(imgbytes);
bmp2.RotateFlip(RotateFlipType.Rotate180FlipX);
bmp2 = ReduceBitmap(bmp2, width, height);
canvas.Clear(System.Drawing.Color.White);
canvas.DrawImage(bmp2, 0, 0);
aviw.AddFrame();
}
}
aviw.Close();
_stored=0;
_complete=0f;
RemoveImages();
}
/**
* Create a movie from the captured shots
* @return void
* @note Pro and Developer Version only
*/
public void CreateMovie(){
int width=320;
int height=240;
int framerate=200;
if(_Filename==""){
_Filename="VidLapse-Video"+DateTime.Now.Millisecond+DateTime.Now.Second;
}
AviWriter aviw = new AviWriter();
Bitmap bmp = aviw.Open(_fullpath+"/"+_Filename+".avi",(uint)framerate,width,height);
System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(bmp);
if (_saveMethod == SaveMethod.Disk) {
DirectoryInfo d = new DirectoryInfo(Application.persistentDataPath + "/");
FileInfo[] files = d.GetFiles("*.png");
foreach (FileInfo file in files) {
Bitmap bmp2 = new Bitmap(file.FullName);
bmp2.RotateFlip(RotateFlipType.Rotate180FlipX);
bmp2 = ReduceBitmap(bmp2, width, height);
canvas.Clear(System.Drawing.Color.White);
canvas.DrawImage(bmp2, 0, 0);
aviw.AddFrame();
}
} else {
for (int i = 0; i < _imageBytes.Count; i++) {
byte[] imgbytes = _imageBytes.Dequeue();
Bitmap bmp2 = ToBitmap(imgbytes);
bmp2.RotateFlip(RotateFlipType.Rotate180FlipX);
bmp2 = ReduceBitmap(bmp2, width, height);
canvas.Clear(System.Drawing.Color.White);
canvas.DrawImage(bmp2, 0, 0);
aviw.AddFrame();
}
}
aviw.Close();
_stored=0;
_complete=0f;
RemoveImages();
}
#region Getters/Setters
/**
* Gets/sets the frequency of image collection
* @return float The frequency the system should collect screenshots
* @note Pro and Developer Version only
*/
public float Frequency{
get{return _frequency;}
set{_frequency=value;}
}
/**
* Gets/sets whether the system should save to desktop
* @return bool Whether or not the system should save to desktop
* @note Pro and Developer Version only
*/
public bool SaveToDesktop{
get{return _savetodesktop;}
set{_savetodesktop=value;}
}
/**
* Gets the total count of images stored
* @return int Count of images stored
* @note Pro and Developer Version only
*/
public int Stored{
get{return _stored;}
private set{_stored=value;}
}
/**
* Gets/sets the finished movie's name
* @return string Finished movie's name
* @note Pro and Developer Version only
*/
public string MovieName{
get{return _Filename;}
set{_Filename=value;}
}
/**
* Gets/sets the Directory to store images
* @return string Directory to store images
* @note Pro and Developer Version only
*/
public string Folder{
get{
if(_fullpathset)
return "";
else
return _directory;
}
set{
if(_fullpathset)
throw new Exception("Cannot set new directory. Full path has already been set!");
_directory=value;}
}
#endregion
}
}
#endif