Windows Phone 8.1 MediaComposition - Audio Too Fast When Stitching Videos

北城余情 提交于 2019-12-05 00:14:25

问题


I am having a problem when trying to concatenate multiple videos together. Whenever I combine 2 or more videos, the audio is played at double speed, while the video plays out normally.

Below is the code. Am I missing something?

I get the same results when testing but cloning a single video or selecting multiple videos.

I have compared to the code example here (I am not trimming).

public static IAsyncOperation<IStorageFile> ConcatenateVideoRT([ReadOnlyArray]IStorageFile[] videoFiles, IStorageFolder outputFolder, string outputfileName)
    {
        return Task.Run<IStorageFile>(async () =>
        {
            IStorageFile _OutputFile = await outputFolder.CreateFileAsync(outputfileName, CreationCollisionOption.GenerateUniqueName);

            MediaComposition _MediaComposition = new MediaComposition();
            foreach (IStorageFile _VideoFile in videoFiles)
            {
                MediaClip _MediaClip = await MediaClip.CreateFromFileAsync(_VideoFile);
                _MediaComposition.Clips.Add(_MediaClip);
                _MediaComposition.Clips.Add(_MediaClip.Clone());
            }

            TranscodeFailureReason _TranscodeFailureReason = await _MediaComposition.RenderToFileAsync(_OutputFile);
            if (_TranscodeFailureReason != TranscodeFailureReason.None)
            {
                throw new Exception("Video Concatenation Failed: " + _TranscodeFailureReason.ToString());
            }

            return _OutputFile;
        }).AsAsyncOperation();
    }

回答1:


It looks like there are two issues. I have got this working by adding the following line:

MediaEncodingProfile _MediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);

And changing the following line:

TranscodeFailureReason _TranscodeFailureReason = await _MediaComposition.RenderToFileAsync(_OutputFile);

To:

TranscodeFailureReason _TranscodeFailureReason = await _MediaComposition.RenderToFileAsync(_OutputFile, MediaTrimmingPreference.Fast, _MediaEncodingProfile);

The problem seems to be that RenderToFileAsync doesn't appear to work properly when using VideoEncodingQuality.HD720p or VideoEncodingQuality.HD1080p, both of these settings recreate the fast audio issue. Also, using VideoEncodingQuality.Auto seems to cause the encode to fail (although I think it is meant to use the default settings from the camera).

Additionally, I posted the problem on the Microsoft Partner Community Forums and their response was that encoding can fail on specific devices, e.g. in their tests video recorded on a Lumia 638 could not be encoded/concatenated even on other devices, but video from a HTC 8x, Lumia 920 and Lumia 930 could be encoded on all devices even the 638.

They suggested this was a device problem (firmware) not a Windows.Media.Editing API problem.



来源:https://stackoverflow.com/questions/28861216/windows-phone-8-1-mediacomposition-audio-too-fast-when-stitching-videos

工具导航Map