如何在Windows Phone 8上从视频文件(.mp4)创建缩略图?

时间:2013-04-24 06:06:12

标签: video windows-phone-8

我使用AudioVideoCapture设计录制视频,但我无法获取录制视频的缩略图。请帮帮我!

1 个答案:

答案 0 :(得分:0)

你可以试试这个。如果您正在使用AudioVideoCaptureDevice api。每次帧捕获后调用以下事件(previewThumbnail)。您可以选择所需的任何框架。先拿一个。

private AudioVideoCaptureDevice VideoRecordingDevice;
VideoRecordingDevice.PreviewFrameAvailable += previewThumbnail;
bool DisablePreviewFrame = false;

private void previewThumbnail(ICameraCaptureDevice a, object b)
{
    if (!DisablePreviewFrame)
    {
        DisablePreviewFrame = true;
        int frameWidth = (int)VideoRecordingDevice.PreviewResolution.Width;
        int frameHeight = (int)VideoRecordingDevice.PreviewResolution.Height;
    }
    int[] buf = new int[frameWidth * frameHeight];
    VideoRecordingDevice.GetPreviewBufferArgb(buf);
    using (IsolatedStorageFile isoStoreFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
        var fileName = "temp.jpg";

        if (isoStoreFile.FileExists(fileName))
            isoStoreFile.DeleteFile(fileName);
        using (IsolatedStorageFileStream isostream = isoStoreFile.CreateFile(fileName))
        {
            WriteableBitmap wb = new WriteableBitmap(frameWidth, frameWidth);
            Array.Copy(buf, wb.Pixels, buf.Length);
            wb.SaveJpeg(isostream, 120, 120, 0, 60);
            isostream.Close();
        }
    }
}