MediaCapture VideoStabilization fails with 0xC00D4A3E

0

I'm working on a video recording app that supports the VideoStabilization effect, but when I start recording, I receive the following through the MediaCapture.Failed event almost instantly:

The sample allocator is currently empty, due to outstanding requests. (0xC00D4A3E)

It only happens when I use the recommended configuration from the effect, though. If I don't call SetUpVideoStabilizationRecommendationAsync, it works fine.

Here is how I'm setting it up:

    private MediaEncodingProfile _encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

    private async Task CreateVideoStabilizationEffectAsync()
    {
        var definition = new VideoStabilizationEffectDefinition();

        _videoStabilizationEffect = (VideoStabilizationEffect)await _mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoRecord);
        _videoStabilizationEffect.Enabled = true;

        await SetUpVideoStabilizationRecommendationAsync();
    }

    private async Task SetUpVideoStabilizationRecommendationAsync()
    {
        var properties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoRecord) as VideoEncodingProperties;
        var recommendation = _videoStabilizationEffect.GetRecommendedStreamConfiguration(_mediaCapture.VideoDeviceController, properties);

        if (recommendation.InputProperties != null)
        {
            await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord, recommendation.InputProperties);
        }

        if (recommendation.OutputProperties != null)
        {
            _encodingProfile.Video = recommendation.OutputProperties;
        }
    }

    private async Task StartRecordingAsync()
    {
        var videoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("StableVideo.mp4", CreationCollisionOption.GenerateUniqueName);
        await _mediaCapture.StartRecordToStorageFileAsync(_encodingProfile, videoFile);
    }
c#
windows-store-apps
win-universal-app
windows-10
asked on Stack Overflow Jun 16, 2015 by Mike

1 Answer

0

The desiredProperties parameter of the GetRecommendedStreamConfiguration method needs to get MediaEncodingProfile that will be used when calling your choice of MediaCapture.StartRecordTo* (i.e. the "output properties") to see what your desired VideoEncodingProperties are.

The error is being triggered because the VideoEncodingProperties from the VideoDeviceController (i.e. the "input properties") are being passed instead. If you think about it, an instance of the the VideoDeviceController is already being passed in as a parameter to the method, so the effect can already access the information in that properties var; it wouldn't make much sense to have to pass those in separately at the same time. Instead, what it needs is information about the other endpoint. Does that make sense? At least that's how I try to rationalize it.

The official SDK sample for VideoStabilization on the Microsoft github repo shows how to do this correctly:

    /// <summary>
    /// Configures the pipeline to use the optimal resolutions for VS based on the settings currently in use
    /// </summary>
    /// <returns></returns>
    private async Task SetUpVideoStabilizationRecommendationAsync()
    {
        Debug.WriteLine("Setting up VS recommendation...");

        // Get the recommendation from the effect based on our current input and output configuration
        var recommendation = _videoStabilizationEffect.GetRecommendedStreamConfiguration(_mediaCapture.VideoDeviceController, _encodingProfile.Video);

        // Handle the recommendation for the input into the effect, which can contain a larger resolution than currently configured, so cropping is minimized
        if (recommendation.InputProperties != null)
        {
            // Back up the current input properties from before VS was activated
            _inputPropertiesBackup = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoRecord) as VideoEncodingProperties;

            // Set the recommendation from the effect (a resolution higher than the current one to allow for cropping) on the input
            await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord, recommendation.InputProperties);
            Debug.WriteLine("VS recommendation for the MediaStreamProperties (input) has been applied");
        }

        // Handle the recommendations for the output from the effect
        if (recommendation.OutputProperties != null)
        {
            // Back up the current output properties from before VS was activated
            _outputPropertiesBackup = _encodingProfile.Video;

            // Apply the recommended encoding profile for the output, which will result in a video with the same dimensions as configured
            // before VideoStabilization was added if an appropriate padded capture resolution was available. Otherwise, it will be slightly
            // smaller (due to cropping). This prevents upscaling back to the original size, which can result in a loss of quality
            _encodingProfile.Video = recommendation.OutputProperties;
            Debug.WriteLine("VS recommendation for the MediaEncodingProfile (output) has been applied");
        }
    }
answered on Stack Overflow Jun 16, 2015 by Mike

User contributions licensed under CC BY-SA 3.0