/// <summary> /// Creates a media target. /// </summary> /// <param name="sinkWriter">The previously created SinkWriter.</param> /// <param name="videoPixelSize">The pixel size of the video.</param> /// <param name="streamIndex">The stream index for the new target.</param> protected override void CreateMediaTarget(MF.SinkWriter sinkWriter, Size2 videoPixelSize, out int streamIndex) { using (MF.MediaType mediaTypeOut = new MF.MediaType()) { mediaTypeOut.Set <Guid>(MF.MediaTypeAttributeKeys.MajorType, MF.MediaTypeGuids.Video); mediaTypeOut.Set <Guid>(MF.MediaTypeAttributeKeys.Subtype, VIDEO_ENCODING_FORMAT); mediaTypeOut.Set <int>(MF.MediaTypeAttributeKeys.AvgBitrate, base.Bitrate * 1000); mediaTypeOut.Set <int>(MF.MediaTypeAttributeKeys.InterlaceMode, (int)MF.VideoInterlaceMode.Progressive); mediaTypeOut.Set <long>(MF.MediaTypeAttributeKeys.FrameSize, MFHelper.GetMFEncodedIntsByValues(videoPixelSize.Width, videoPixelSize.Height)); mediaTypeOut.Set <long>(MF.MediaTypeAttributeKeys.FrameRate, MFHelper.GetMFEncodedIntsByValues(base.Framerate, 1)); sinkWriter.AddStream(mediaTypeOut, out streamIndex); } }
public MediaFoundationAudioWriter(MF.SinkWriter sinkWriter, ref WAVEFORMATEX waveFormat, int desiredBitRate = 192000) { var sharpWf = waveFormat.ToSharpDX(); // Information on configuring an AAC media type can be found here: // http://msdn.microsoft.com/en-gb/library/windows/desktop/dd742785%28v=vs.85%29.aspx var outputMediaType = SelectMediaType(AudioFormat, sharpWf, desiredBitRate); if (outputMediaType == null) { throw new InvalidOperationException("No suitable encoders available"); } var inputMediaType = new MF.MediaType(); var size = 18 + sharpWf.ExtraSize; sinkWriter.AddStream(outputMediaType, out streamIndex); MF.MediaFactory.InitMediaTypeFromWaveFormatEx(inputMediaType, new[] { sharpWf }, size); sinkWriter.SetInputMediaType(streamIndex, inputMediaType, null); }