namespace Camera.Software;
public partial class Video
{
public Video() => _ = Constructor();
private async Task Constructor()
{
Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
//choice .mp4 easy to work whit
Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync(Guid.NewGuid().ToString() + ".mp4");
var b = await sampleFile.OpenStreamForWriteAsync();
var c = await sampleFile.OpenStreamForReadAsync();
//find video devices i can also find audio but i only choice to find video
var videoCaptures = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
//if i need Audio i can place it AudioDeviceId then i have audio to
MediaCaptureInitializationSettings mediaCaptureSettings = new () { VideoDeviceId = videoCaptures.First().Id };
//well as i say there many format i can work easy whit mp4
var mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
InMemoryRandomAccessStream inMemoryRandomAccessStream = new();
MediaCapture mediaCapture = new();
await mediaCapture.InitializeAsync(mediaCaptureSettings);
await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, inMemoryRandomAccessStream);
//need to lower the sening to server so i dont send alot of data
int LastPosition = 0;
while (true) {
using var memoryStream = new MemoryStream();
inMemoryRandomAccessStream.GetInputStreamAt(0).AsStreamForRead().CopyTo(memoryStream);
//why send all to server
var a = memoryStream.ToArray().Skip(LastPosition).ToArray();
LastPosition += a.Count();
//yes from her i can stream the data to what to ever server and so on
if(a.Length> 0)
await b.WriteAsync(a);
//make sure not to limit the stream like small restart
if (inMemoryRandomAccessStream.Position >= 2000000000)
{
//yes a quick restart
await mediaCapture.StopRecordAsync();
LastPosition = 0;
inMemoryRandomAccessStream.Dispose();
inMemoryRandomAccessStream = new();
await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, inMemoryRandomAccessStream);
continue;
}
}
}
}