MediaEncodingProfile"没有找到合适的转换来编码或解码内容。"例外

时间:2014-06-11 08:16:23

标签: windows-phone-8 video-capture windows-phone-8.1

使用MediaCapture在Windows Phone 8.1 Silverlight上录制视频时,我得到例外情况“找不到合适的转换来编码或解码内容。”创建要记录到.wmv的配置文件时:

MediaEncodingProfile profile = MediaEncodingProfile.CreateWmv(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);

但我找不到任何有关如何应用转换的文档或帖子。有人可以帮忙吗?

[EDIT]完整代码如下:

//PreviewSink for previewing video
    MediaCapturePreviewSink previewSink = new MediaCapturePreviewSink();

    //Viewfinder for viewing video.
    private VideoBrush videoRecorderBrush;

    //Profile for setting up capture type
    MediaEncodingProfile _profile;

    //MediaCapture for recording video
    MediaCapture mediaCaptureManager = new MediaCapture();

    // File details for storing the recording.        
    private IsolatedStorageFileStream isoVideoFile;
    private string isoVideoFileName = "CameraMovie.mp4";

    // For managing button and application state.
    private enum ButtonState { Initialized, Ready, Recording, Playback, Paused, NoChange, CameraNotSupported };
    private ButtonState currentAppState;

//PREVIEW/VIEWFINDER

    //Start the video preview when the page loads
    private async void StartPreview()
    {
        //INITIALIZE
        await subInitialise();

        //PREVIEW
        await subPreview();
    }

    //Initilize MediaCapture for previewing
    private async System.Threading.Tasks.Task subInitialise()
    {
        // Find the camera device id to use
        string deviceId = "";
        var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
        for (var i = 0; i < devices.Count; i++)
        {
            Debug.WriteLine(devices[i]);
            deviceId = devices[i].Id;
        }

        // init the settings of the capture
        var settings = new MediaCaptureInitializationSettings();
        settings.AudioDeviceId = "";
        settings.VideoDeviceId = deviceId;
        settings.MediaCategory = MediaCategory.Other;
        settings.PhotoCaptureSource = PhotoCaptureSource.Photo;
        settings.StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo;

        //This creates the recording media profile
        CreateProfile();

        await mediaCaptureManager.InitializeAsync(settings);
    }

    //Create the MediaEncodingProfile
    private void CreateProfile()
    {
        //WORKS
        //_profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Qvga);
        //DOESN'T WORK
         _profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateWmv(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);

    }

    //Set up the MediaCapture for previewing and start preview
    private async System.Threading.Tasks.Task subPreview()
    {
        //MediaCapturePreviewSink previewSink = new MediaCapturePreviewSink();
        // List of supported video preview formats to be used by the default preview format selector.
        var supportedVideoFormats = new List<string> { "nv12", "rgb32" };

        // Find the supported preview format
        var availableMediaStreamProperties = mediaCaptureManager.VideoDeviceController.GetAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.VideoPreview).OfType<Windows.Media.MediaProperties.VideoEncodingProperties>().Where(p => p != null && !String.IsNullOrEmpty(p.Subtype) && supportedVideoFormats.Contains(p.Subtype.ToLower())).ToList();
        var previewFormat = availableMediaStreamProperties.FirstOrDefault();

        // Start Preview stream
        await mediaCaptureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.VideoPreview, previewFormat);
        await mediaCaptureManager.StartPreviewToCustomSinkAsync(new Windows.Media.MediaProperties.MediaEncodingProfile { Video = previewFormat }, previewSink);

        // Create the VideoBrush for the viewfinder.
        videoRecorderBrush = new VideoBrush();
        // Set the source of the VideoBrush used for your preview
        Microsoft.Devices.CameraVideoBrushExtensions.SetSource(videoRecorderBrush, previewSink);
        // Display the viewfinder image on the rectangle.
        viewfinderRectangle.Fill = videoRecorderBrush;

        //Set the button states and the message.
        UpdateUI(ButtonState.Initialized, "Ready to record.");
    }

//Start recording
    private async void StartVideoRecordingNew()
    {
        try
        {
            // Get the local folder.
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            // Create a new file named DataFile.txt.
            var storageFile = await local.CreateFileAsync(isoVideoFileName, CreationCollisionOption.ReplaceExisting);

            await mediaCaptureManager.StartRecordToStorageFileAsync(_profile, storageFile);

            // Set the button states and the message.
            UpdateUI(ButtonState.Recording, "Recording...");
        }

        // If recording fails, display an error.
        catch (Exception e)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                txtDebug.Text = "ERROR: " + e.Message.ToString();
            });
        }
    }

1 个答案:

答案 0 :(得分:0)

您是否尝试使用MediaCapturePreviewSink http://msdn.microsoft.com/en-us/library/dn655126(v=vs.105).aspx