Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
11 views
in Technique[技术] by (71.8m points)

c# - Windows Phone 8.1 MediaComposition - Audio Too Fast When Stitching Videos

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();
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...