Search code examples
c#windows-store-appswindows-8.1

How to get thumbnail from a video in Windows Store app?


I am currently working on an app in which there is feature to record video. I am aware about how to record the video and save it in localFolder of app. My problem is that I need to show a thumbnail to user after he records the video. So, for that I want to extract the first frame from the recorded video. The final video is stored in StorageFile object but I am not aware how to get image from StorageFile object.

Please can anyone suggest with some sample code how can I do that. I am using default Camera API for recording video. My code is below

private async void CaptureVideo()
{
    CameraCaptureUI cameraUI = new CameraCaptureUI();
    cameraUI.VideoSettings.Format=CameraCaptureUIVideoFormat.Mp4;
    cameraUI.VideoSettings.MaxDurationInSeconds = 10;
    StorageFile capturedVideo = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Video);
    string videoName="video_" + GetDateTimestamp() +".mp4";
    if(capturedVideo !=null)
    {
        saveVideoandShowThumbnail(capturedVideo, videoName);
    }
}

Here in saveVideoandShowThumbnail() method is to store the video in Videos Folder and generate the thumbnail.


Solution

  • StorageFile.GetThumbnailAsync() solved my issue. I tried to show image from video using below code. Hope it helps someone

    bitmap = new BitmapImage();
    bitmap.SetSource(await videoFile.GetThumbnailAsync(ThumbnailMode.SingleItem));