简体   繁体   中英

Capture webcamera and save into azure blob storage using UWP C# (mediaCapture)

I have UWP C# app which should record video from webcamera.

Once user hits 'Start Record' I should capture video and save into azure blob storage. So for capturing the webcamera I use mediaCapture.

At this moment I can save into local storage using the following code

// Create storage file for the capture
var videoFile = await _captureFolder.CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption.GenerateUniqueName);
var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
// Calculate rotation angle, taking mirroring into account if necessary
var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetCameraCaptureOrientation());
encodingProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));

Debug.WriteLine("Starting recording to " + videoFile.Path);

await _mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoFile);
_isRecording = true;

Debug.WriteLine("Started recording!");

However my goal is to start upload into Azure blob using Azure.Storage.Blobs directly without saving in local machine.

Any advice please?

Blob Storage allows you to upload your file in chunks [spliting file in smaller size] and once you're done you can commit these chunks in a specific order:

Try with these methods,

  1. Put Block : Upload a chunk .

  2. PutBlockList : Commit a list of chunks in a specific order

With these methods you can for example create a buffer in memory which stores the video and call PutBlock each time the buffer reaches a certain size. Then, once the recording is done you can call PutBlockList to commit all blocks. As a result, your blob will contain the complete recording without saving it to local disk first.

How to use these methods refer this document and SO Thread

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM