/// <summary>
        /// Starts rendering to the target.
        /// </summary>
        /// <param name="videoPixelSize">The pixel size of the video.</param>
        protected override void StartRenderingInternal(Size2 videoPixelSize)
        {
            m_outStreamNet = base.TargetFile.OpenOutputStream();
            m_outStream    = new MF.ByteStream(m_outStreamNet);

            // Pass dummy filename as described here:
            // https://social.msdn.microsoft.com/forums/windowsapps/en-us/49bffa74-4e84-4fd6-9d67-42e8385611b8/video-sinkwriter-in-metro-app
            m_sinkWriter = MF.MediaFactory.CreateSinkWriterFromURL(
                this.DummyFileName, m_outStream.NativePointer, null);
            m_videoPixelSize = videoPixelSize;

            CreateMediaTarget(m_sinkWriter, m_videoPixelSize, out m_streamIndex);

            // Configure input
            using (MF.MediaType mediaTypeIn = new MF.MediaType())
            {
                mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video);
                mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.Subtype, VIDEO_INPUT_FORMAT);
                mediaTypeIn.Set <int>(MF.MediaTypeAttributeKeys.InterlaceMode, (int)MF.VideoInterlaceMode.Progressive);
                mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameSize, MFHelper.GetMFEncodedIntsByValues(videoPixelSize.Width, videoPixelSize.Height));
                mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameRate, MFHelper.GetMFEncodedIntsByValues(m_framerate, 1));
                m_sinkWriter.SetInputMediaType(m_streamIndex, mediaTypeIn, null);
            }

            // Start writing the video file
            m_sinkWriter.BeginWriting();

            // Set initial frame index
            m_frameIndex = -1;
        }
예제 #2
0
        public MediaFoundationVideoWriter(string filePath, Size2 videoPixelSize, Guid videoInputFormat, bool supportAudio = false)
        {
            bitrate   = 1500000;
            framerate = 15;

            if (!MFInitialized)
            {
                // Initialize MF library. MUST be called before any MF related operations.
                MF.MediaFactory.Startup(MF.MediaFactory.Version, 0);
            }

            sinkWriter = MF.MediaFactory.CreateSinkWriterFromURL(filePath, IntPtr.Zero, null);

            this.videoPixelSize = videoPixelSize;
            CreateMediaTarget(sinkWriter, videoPixelSize, out streamIndex);

            // Configure input
            using (MF.MediaType mediaTypeIn = new MF.MediaType())
            {
                mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video);
                mediaTypeIn.Set <Guid>(MF.MediaTypeAttributeKeys.Subtype, videoInputFormat);
                mediaTypeIn.Set <int>(MF.MediaTypeAttributeKeys.InterlaceMode, (int)MF.VideoInterlaceMode.Progressive);
                mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameSize, MFHelper.GetMFEncodedIntsByValues(videoPixelSize.Width, videoPixelSize.Height));
                mediaTypeIn.Set <long>(MF.MediaTypeAttributeKeys.FrameRate, MFHelper.GetMFEncodedIntsByValues(framerate, 1));
                sinkWriter.SetInputMediaType(streamIndex, mediaTypeIn, null);
            }

            if (supportAudio)
            {
                // initialize audio writer
                var waveFormat = WAVEFORMATEX.DefaultPCM;
                audioWriter = new MP3AudioWriter(sinkWriter, ref waveFormat);
            }

            // Start writing the video file. MUST be called before write operations.
            sinkWriter.BeginWriting();

            // Set initial frame index
            frameIndex = -1;
        }
        public MediaFoundationVideoWriter(string filePath, Size2 videoPixelSize, Guid videoInputFormat, bool supportAudio = false)
        {
            bitrate = 1500000;
            framerate = 15;

            if (!MFInitialized)
            {
                // Initialize MF library. MUST be called before any MF related operations.
                MF.MediaFactory.Startup(MF.MediaFactory.Version, 0);
            }

            sinkWriter = MF.MediaFactory.CreateSinkWriterFromURL(filePath, IntPtr.Zero, null);

            this.videoPixelSize = videoPixelSize;
            CreateMediaTarget(sinkWriter, videoPixelSize, out streamIndex);

            // Configure input
            using (MF.MediaType mediaTypeIn = new MF.MediaType())
            {
                mediaTypeIn.Set<Guid>(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video);
                mediaTypeIn.Set<Guid>(MF.MediaTypeAttributeKeys.Subtype, videoInputFormat);
                mediaTypeIn.Set<int>(MF.MediaTypeAttributeKeys.InterlaceMode, (int)MF.VideoInterlaceMode.Progressive);
                mediaTypeIn.Set<long>(MF.MediaTypeAttributeKeys.FrameSize, MFHelper.GetMFEncodedIntsByValues(videoPixelSize.Width, videoPixelSize.Height));
                mediaTypeIn.Set<long>(MF.MediaTypeAttributeKeys.FrameRate, MFHelper.GetMFEncodedIntsByValues(framerate, 1));
                sinkWriter.SetInputMediaType(streamIndex, mediaTypeIn, null);
            }

            if (supportAudio)
            {
                // initialize audio writer
                var waveFormat = WAVEFORMATEX.DefaultPCM;
                audioWriter = new MP3AudioWriter(sinkWriter, ref waveFormat);
            }

            // Start writing the video file. MUST be called before write operations.
            sinkWriter.BeginWriting();

            // Set initial frame index
            frameIndex = -1;
        }