public static MediaFoundationStreamingSources CreateFromFile(DXGIDeviceManager dxgiDeviceManager, VariablePath ファイルパス, WaveFormat soundDeviceFormat) { var sources = new MediaFoundationStreamingSources(); #region " ファイルから SourceReaderEx を生成する。" //---------------- using (var ビデオ属性 = new MediaAttributes()) { // DXVAに対応しているGPUの場合には、それをデコードに利用するよう指定する。 ビデオ属性.Set(SourceReaderAttributeKeys.D3DManager, dxgiDeviceManager); // 追加のビデオプロセッシングを有効にする。 ビデオ属性.Set(SourceReaderAttributeKeys.EnableAdvancedVideoProcessing, true); // 真偽値が bool だったり // 追加のビデオプロセッシングを有効にしたら、こちらは無効に。 ビデオ属性.Set(SinkWriterAttributeKeys.ReadwriteDisableConverters, 0); // int だったり // 属性を使って、SourceReaderEx を生成。 using (var sourceReader = new SourceReader(ファイルパス.数なしパス, ビデオ属性)) // パスは URI 扱い sources._SourceReaderEx = sourceReader.QueryInterface <SourceReaderEx>(); } //---------------- #endregion #region " WaveFormat を生成。" //---------------- sources._Audioのフォーマット = new WaveFormat( soundDeviceFormat.SampleRate, 32, soundDeviceFormat.Channels, AudioEncoding.IeeeFloat); //---------------- #endregion sources._SourceReaderEx生成後の初期化(); return(sources); }
public static MediaFoundationStreamingSources CreateFromニコ動(string user_id, string password, string video_id, WaveFormat soundDeviceFormat) { var sources = new MediaFoundationStreamingSources(); #region " ニコ動から SourceReaderEx を生成する。" //---------------- if (null == _HttpClient) { _HttpClient = new HttpClient(); } // ログインする。 var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "mail", user_id }, { "password", password }, { "next_url", string.Empty }, }); using (var responseLogin = _HttpClient.PostAsync("https://secure.nicovideo.jp/secure/login?site=niconico", content).Result) { } // 動画ページにアクセスする。(getflvより前に) var responseWatch = _HttpClient.GetStringAsync($"http://www.nicovideo.jp/watch/{video_id}").Result; // 動画情報を取得する。 var responseGetFlv = _HttpClient.GetStringAsync($"http://flapi.nicovideo.jp/api/getflv/{video_id}").Result; var flvmap = HttpUtility.ParseQueryString(responseGetFlv); var flvurl = flvmap["url"]; // 動画の長さを取得する。 ulong 長さbyte = 0; string contentType = ""; using (var requestMovie = new HttpRequestMessage(HttpMethod.Get, flvurl)) using (var responseMovie = _HttpClient.SendAsync(requestMovie, HttpCompletionOption.ResponseHeadersRead).Result) { 長さbyte = (ulong)(responseMovie.Content.Headers.ContentLength); contentType = responseMovie.Content.Headers.ContentType.MediaType; } // IMFByteStream を生成する。 sources._ByteStream = new ByteStream(IntPtr.Zero); sources._HttpRandomAccessStream = new HttpRandomAccessStream(_HttpClient, 長さbyte, flvurl); sources._unkHttpRandomAccessStream = new ComObject(Marshal.GetIUnknownForObject(sources._HttpRandomAccessStream)); MediaFactory.CreateMFByteStreamOnStreamEx(sources._unkHttpRandomAccessStream, sources._ByteStream); using (var 属性 = sources._ByteStream.QueryInterfaceOrNull <MediaAttributes>()) { // content-type を設定する。 属性.Set(ByteStreamAttributeKeys.ContentType, contentType); } // SourceResolver で IMFByteStream から MediaSouce を取得する。 using (var sourceResolver = new SourceResolver()) using (var unkMediaSource = sourceResolver.CreateObjectFromStream(sources._ByteStream, null, SourceResolverFlags.MediaSource)) { sources._MediaSource = unkMediaSource.QueryInterface <MediaSource>(); // MediaSource から SourceReaderEx を生成する。 using (var 属性 = new MediaAttributes()) { // DXVAに対応しているGPUの場合には、それをデコードに利用するよう指定する。 属性.Set(SourceReaderAttributeKeys.D3DManager, グラフィックデバイス.Instance.MFDXGIDeviceManager); // 追加のビデオプロセッシングを有効にする。 属性.Set(SourceReaderAttributeKeys.EnableAdvancedVideoProcessing, true); // 真偽値が bool だったり // 追加のビデオプロセッシングを有効にしたら、こちらは無効に。 属性.Set(SinkWriterAttributeKeys.ReadwriteDisableConverters, 0); // int だったり // 属性を使って、SourceReaderEx を生成。 using (var sourceReader = new SourceReader(sources._MediaSource, 属性)) { sources._SourceReaderEx = sourceReader.QueryInterfaceOrNull <SourceReaderEx>(); } } } //---------------- #endregion #region " WaveFormat を生成。" //---------------- sources._Audioのフォーマット = new WaveFormat( soundDeviceFormat.SampleRate, 32, soundDeviceFormat.Channels, AudioEncoding.IeeeFloat); //---------------- #endregion sources._SourceReaderEx生成後の初期化(); return(sources); }