1

I'm trying to create a Video with an Image using MediaTranscoder class in WindowsPhone 8.1 SDK. If I succeed I would then use it to create a video with more images.

in the code below I find an image inside the pictures library and create a MediaStreamSample from it. this works fine!

then I create a MediaStreamSource with duration of 1 (Sec) and relate it to the sample I Created before. this works fine too!

What doesn't work is the MediaTranscoder instance.

await transcoder.PrepareMediaStreamSourceTranscodeAsync(src, ras, profile);

when I call the above method I get a "Reference not set to an instance" exception. (null Reference exception)

I don't know why this happens... please help me.

StorageFolder cameraFolder = KnownFolders.CameraRoll;
        IReadOnlyList<StorageFile> fileList = await cameraFolder.GetFilesAsync();

        var query = fileList.Where(f => f.Name.StartsWith("JeyLapse")).ToList();

        var stream = await query[0].OpenStreamForReadAsync();

        MediaStreamSample sample =
            await MediaStreamSample.CreateFromStreamAsync(stream.AsInputStream(), (uint)stream.Length, new TimeSpan());


        MediaStreamSource src = new MediaStreamSource(new VideoStreamDescriptor(VideoEncodingProperties.CreateMpeg2()));
        src.Duration = TimeSpan.FromSeconds(1);

        src.SampleRequested += (sender, args) =>
        {
            args.Request.Sample = sample;
        };

        src.Starting += (sender, args) => args.Request.SetActualStartPosition(new TimeSpan());
        src.SwitchStreamsRequested += (sender, args) => args.Request.GetDeferral().Complete();

        MediaTranscoder transcoder = new MediaTranscoder();
        MediaEncodingProfile profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

        var newFile = await KnownFolders.VideosLibrary.CreateFileAsync("tryJeylapse", CreationCollisionOption.GenerateUniqueName);
        var writestr = await newFile.OpenStreamForWriteAsync();

        var ras = writestr.AsRandomAccessStream();
        transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default;

        var trans = await transcoder.PrepareMediaStreamSourceTranscodeAsync(src, ras, profile);
        await trans.TranscodeAsync();
uncommon_name
  • 470
  • 2
  • 5
  • 19

0 Answers0