Last updated: 2026年1月
DirectShow.NET の代替:VisioForge .Net SDK への移行ガイド
DirectShow.NET(開発終了)から VisioForge .NET SDK への移行ステップバイステップガイド。.NET 6-10 でのビデオキャプチャ、再生、処理に対応。
DirectShow.NET(directshowlib)からモダンな .NET 6-10 ビデオキャプチャ、再生、処理 SDK へ移行する C# 開発者向け
なぜ DirectShow.NET を置き換えるべきか?
DirectShow.NET は2010年2月以降放棄されています — 15年以上アップデートなし。Microsoft の DirectShow API の生の COM インターフェース定義を提供していますが、Microsoft 自体が Media Foundation を推奨して DirectShow を非推奨にしています。
| リスク | 影響 |
|---|---|
| Microsoft が DirectShow を非推奨化 | 新機能、コーデック、プラットフォームサポートなし |
| ライブラリがメンテナンスされていない | .NET Framework 2.0、.NET 6+ サポートなし |
| COM の複雑さ | 基本的なタスクに数百行、手動メモリ管理 |
| コーデック探し | サードパーティの DirectShow フィルターを探し、インストール、登録する必要あり |
| フィルターグラフのデバッグ | 不透明なパイプライン障害、診断ツールなし |
| Windows のみ | COM/DirectShow は macOS、Linux、モバイルでは実行不可 |
| モダンなコーデックなし | サードパーティフィルターなしではネイティブ H.265、AV1、VP9 なし |
| レジストリの問題 | モダン Windows でのフィルター登録の問題 |
DirectShowの概念解説
DirectShowのアーキテクチャがVisioForge SDKにどのようにマッピングされるかを理解することで、移行計画を立てやすくなります。以下の表は、DirectShowの各コア概念が最新の.NET相当のものにどのように変換されるかを示しています。
DirectShowアーキテクチャからVisioForge相当へ
| DirectShowの概念 | VisioForge相当 |
|---|---|
| Filter Graph (IGraphBuilder) | パイプライン — SDKが自動管理、または明示的なMediaBlocksPipeline |
| Source Filter(デバイス/ファイル) | ソース設定:VideoCaptureDeviceSourceSettings、RTSPSourceSettings等 |
| Transform Filter(エフェクト/エンコーダー) | 内蔵ビデオ/オーディオエフェクト + エンコーダークラス(H264EncoderSettings等) |
| Renderer Filter(ビデオウィンドウ) | VideoViewコントロール(WinForms、WPF、MAUI、Avalonia) |
| Mux Filter(AVI/MP4 mux) | 出力フォーマットクラス:MP4Output、AVIOutput、MKVOutput、WebMOutput |
| ピン接続 | 自動 — またはMedia Blocks SDKでの明示的なBlock.Connect() |
| メディアタイプ(AM_MEDIA_TYPE) | 自動処理 — 手動のフォーマットネゴシエーション不要 |
| フィルターカテゴリ(デバイス列挙) | DeviceEnumerator.Shared.VideoSourcesAsync() / AudioSourcesAsync() |
| DirectShowフィルター登録(regsvr32) | NuGetパッケージ — システム登録不要 |
| GraphEditデバッグツール | パイプラインイベント、ロギング、型付き例外 |
どの VisioForge SDK が何を置き換えるか?
DirectShow.NET の使用法から VisioForge への置き換え
| DirectShow.NET の使用法 | VisioForge の置き換え |
|---|---|
| フィルターグラフによる C# ウェブカメラキャプチャ | Video Capture SDK .Net — `VideoCaptureCoreX` |
| C# IP カメラキャプチャ(RTSP/MJPEG) | Video Capture SDK .Net — `RTSPSourceSettings` |
| C# 画面キャプチャと録画 | Video Capture SDK .Net — `ScreenCaptureSourceSettings` |
| `IGraphBuilder` によるファイル再生 | Media Player SDK .Net — `MediaPlayerCoreX` |
| `IDvdControl2` による DVD 再生 | Media Player SDK .Net — DVD ナビゲーション API |
| `IAMTVTuner` による TV チューナー | Video Capture SDK .Net — `VideoCaptureCore` |
| ファイルトランスコーディング | Video Edit SDK .Net — `VideoEditCoreX` |
| カスタムフィルターグラフ | Media Blocks SDK .Net — モジュラーパイプライン(400+ ブロック) |
| `ISampleGrabber` フレームアクセス | 任意の SDK の `OnVideoFrameBuffer` イベント |
C# DirectShow インターフェースマッピング
C# DirectShow インターフェースマッピング
| DirectShow.NET インターフェース | VisioForge 同等機能 |
|---|---|
| `IGraphBuilder` | SDK がパイプラインを自動構築 |
| `ICaptureGraphBuilder2` | `VideoCaptureCoreX` コンストラクター |
| `IMediaControl` (Run/Stop/Pause) | `StartAsync()` / `StopAsync()` / `PauseAsync()` |
| `IMediaEvent` | SDK イベント(`OnError`、`OnStop` など) |
| `IVideoWindow` | `VideoView` コントロール(WinForms/WPF/MAUI/Avalonia) |
| `ISampleGrabber` | `OnVideoFrameBuffer` イベント |
| `IBaseFilter` | 不要 — SDK がフィルターを内部で管理 |
| `IPin` / ピン接続 | 不要 — SDK がパイプラインを自動接続 |
| `DsDevice.GetDevicesOfCat()` | `DeviceEnumerator.Shared.VideoSourcesAsync()` |
| `FilterCategory.VideoInputDevice` | `DeviceEnumerator.Shared.VideoSourcesAsync()` |
| `FilterCategory.AudioInputDevice` | `DeviceEnumerator.Shared.AudioSourcesAsync()` |
| `IAMTVTuner` | `VideoCaptureCore.TVTuner` プロパティ |
| `IDvdControl2` | `MediaPlayerCore.DVD_*` メソッド |
| `Marshal.ReleaseComObject()` | `await sdk.DisposeAsync()` |
C# ウェブカメラキャプチャとプレビュー
DirectShow.NET — ウェブカメラキャプチャ(移行前)
C#// 80+ lines of COM interop
var graphBuilder = (IGraphBuilder)new FilterGraph();
var captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
int hr = captureGraph.SetFiltergraph(graphBuilder);
DsError.ThrowExceptionForHR(hr);
// Find video device
var devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
IBaseFilter sourceFilter;
hr = graphBuilder.AddSourceFilterForMoniker(
devices[0].Mon, null, devices[0].Name, out sourceFilter);
DsError.ThrowExceptionForHR(hr);
// Render preview
hr = captureGraph.RenderStream(
PinCategory.Preview, MediaType.Video, sourceFilter, null, null);
DsError.ThrowExceptionForHR(hr);
// Set video window
var videoWindow = (IVideoWindow)graphBuilder;
videoWindow.put_Owner(panelHandle);
videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
videoWindow.SetWindowPosition(0, 0, panel.Width, panel.Height);
// Start
var mediaControl = (IMediaControl)graphBuilder;
hr = mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
// Cleanup (must release EVERY COM object)
Marshal.ReleaseComObject(sourceFilter);
Marshal.ReleaseComObject(captureGraph);
Marshal.ReleaseComObject(graphBuilder);VisioForge — C# ウェブカメラキャプチャ(移行後)
C#var capture = new VideoCaptureCoreX(videoView);
var devices = await DeviceEnumerator.Shared.VideoSourcesAsync();
capture.Video_Source = new VideoCaptureDeviceSourceSettings(devices[0]);
await capture.StartAsync();
// Cleanup
await capture.StopAsync();
await capture.DisposeAsync();C# ウェブカメラ録画(MP4)
DirectShow.NET — ウェブカメラから MP4(移行前)
C#// Must find H.264 encoder filter, MP4 mux filter, file writer
// Each requires separate COM object management
var graphBuilder = (IGraphBuilder)new FilterGraph();
var captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
captureGraph.SetFiltergraph(graphBuilder);
// Add source
var devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
IBaseFilter sourceFilter;
graphBuilder.AddSourceFilterForMoniker(
devices[0].Mon, null, devices[0].Name, out sourceFilter);
// Find and add H.264 encoder (must be installed on system!)
// This varies by system — no guarantee the filter exists
Guid h264Clsid = new Guid("some-encoder-guid");
IBaseFilter encoder = (IBaseFilter)Activator.CreateInstance(
Type.GetTypeFromCLSID(h264Clsid));
graphBuilder.AddFilter(encoder, "H.264 Encoder");
// Find and add MP4 mux
// Find and add file writer
// Connect source → encoder → mux → writer pins manually
// Each pin connection can fail silently or throw cryptic COM errors
// Configure encoder properties via ICodecAPI or IPropertyBag
// Different for every encoder filter...
var mediaControl = (IMediaControl)graphBuilder;
mediaControl.Run();
// Cleanup: release 5+ COM objectsVisioForge — C# ウェブカメラ録画 MP4(移行後)
C#var capture = new VideoCaptureCoreX(videoView);
var devices = await DeviceEnumerator.Shared.VideoSourcesAsync();
capture.Video_Source = new VideoCaptureDeviceSourceSettings(devices[0]);
capture.Outputs_Add(new MP4Output("recording.mp4"), true);
await capture.StartAsync();C# ビデオファイル再生
DirectShow.NET — ビデオ再生(移行前)
C#var graphBuilder = (IGraphBuilder)new FilterGraph();
int hr = graphBuilder.RenderFile("video.mp4", null);
DsError.ThrowExceptionForHR(hr);
var videoWindow = (IVideoWindow)graphBuilder;
videoWindow.put_Owner(panelHandle);
videoWindow.put_WindowStyle(WindowStyle.Child);
videoWindow.SetWindowPosition(0, 0, panel.Width, panel.Height);
var mediaControl = (IMediaControl)graphBuilder;
mediaControl.Run();
// Seeking
var mediaSeeking = (IMediaSeeking)graphBuilder;
long position = 50000000; // 5 seconds in 100ns units
mediaSeeking.SetPositions(
ref position, AMSeekingSeekingFlags.AbsolutePositioning,
null, AMSeekingSeekingFlags.NoPositioning);VisioForge — C# ビデオプレーヤー(移行後)
C#var player = new MediaPlayerCoreX(videoView);
await player.OpenAsync(new Uri("video.mp4"));
await player.PlayAsync();
// Seeking
await player.SeekAsync(TimeSpan.FromSeconds(5));C# ビデオフレームキャプチャ
DirectShow.NET — ISampleGrabber フレームキャプチャ(移行前)
C#// Must insert ISampleGrabber into filter graph
var sampleGrabber = (ISampleGrabber)new SampleGrabber();
var mediaType = new AMMediaType();
mediaType.majorType = MediaType.Video;
mediaType.subType = MediaSubType.RGB24;
sampleGrabber.SetMediaType(mediaType);
graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "Grabber");
// Connect pins...
sampleGrabber.SetBufferSamples(true);
// In callback: manually read buffer, create Bitmap from raw bytes
sampleGrabber.GetCurrentBuffer(ref bufferSize, buffer);
// Manual pixel format conversion, stride calculation, etc.VisioForge — C# ビデオフレームキャプチャ(移行後)
C#capture.OnVideoFrameBuffer += (s, e) =>
{
// Frame data available as managed buffer
// Or convert to SKBitmap/Bitmap directly
var bitmap = e.Frame.ToBitmap();
ProcessFrame(bitmap);
};C# IPカメラ(RTSP)キャプチャ
DirectShow.NET — RTSPキャプチャ(移行前)
C#// Must find and install RTSP source filter (e.g., LAV, ffdshow)
// No standard DirectShow RTSP filter ships with Windows
var graphBuilder = (IGraphBuilder)new FilterGraph();
// Add RTSP source filter (if installed)
Guid rtspFilterClsid = new Guid("some-rtsp-filter-guid");
IBaseFilter rtspSource = (IBaseFilter)Activator.CreateInstance(
Type.GetTypeFromCLSID(rtspFilterClsid));
graphBuilder.AddFilter(rtspSource, "RTSP Source");
// Configure URL via IFileSourceFilter or custom interface
var fileSource = (IFileSourceFilter)rtspSource;
fileSource.Load("rtsp://camera-ip:554/stream", null);
// Must manually connect pins to decoder, renderer
// No reconnection logic — if stream drops, graph stops
// No authentication helpers
// No ONVIF supportVisioForge — RTSPキャプチャ(移行後)
C#var capture = new VideoCaptureCoreX(videoView);
capture.Video_Source = new RTSPSourceSettings(
new Uri("rtsp://camera-ip:554/stream"))
{
Login = "admin",
Password = "password",
ReconnectOnDrop = true
};
capture.Outputs_Add(new MP4Output("recording.mp4"), true);
await capture.StartAsync();C# スクリーンキャプチャと録画
DirectShow.NET — スクリーンキャプチャ(移行前)
C#// DirectShow has no built-in screen capture filter
// Must use third-party filter or custom push source
// Common approach: manually capture GDI/BitBlt in a thread,
// feed frames through a custom IBaseFilter implementation
// 200+ lines of custom filter code:
// - Implement IBaseFilter, IPin, IMediaSample
// - Manual frame rate timing with Thread.Sleep
// - Manual pixel format conversion
// - No GPU acceleration
// - No mouse cursor rendering
// - No multi-monitor supportVisioForge — スクリーンキャプチャ(移行後)
C#var capture = new VideoCaptureCoreX(videoView);
capture.Video_Source = new ScreenCaptureSourceSettings()
{
FrameRate = new VideoFrameRate(30),
Rectangle = new Rect(0, 0, 1920, 1080),
CaptureCursor = true
};
capture.Outputs_Add(new MP4Output("screen.mp4"), true);
await capture.StartAsync();C# マイクからの音声録音
DirectShow.NET — 音声キャプチャ(移行前)
C#var graphBuilder = (IGraphBuilder)new FilterGraph();
var captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
captureGraph.SetFiltergraph(graphBuilder);
// Find audio device
var audioDevices = DsDevice.GetDevicesOfCat(
FilterCategory.AudioInputDevice);
IBaseFilter audioSource;
graphBuilder.AddSourceFilterForMoniker(
audioDevices[0].Mon, null, audioDevices[0].Name,
out audioSource);
// Must find WAV/MP3 encoder filter
// Must find file writer filter
// Must connect pins manually
// Configure sample rate/channels via IAMStreamConfig
var mediaControl = (IMediaControl)graphBuilder;
mediaControl.Run();
// Manual COM cleanup for all objectsVisioForge — 音声キャプチャ(移行後)
C#var capture = new VideoCaptureCoreX();
var audioDevices = await DeviceEnumerator.Shared
.AudioSourcesAsync();
capture.Audio_Source = new AudioCaptureDeviceSourceSettings(
audioDevices[0]);
capture.Audio_Record = true;
capture.Video_Record = false;
capture.Outputs_Add(new MP4Output("audio.mp4"), true);
await capture.StartAsync();C# カスタム処理パイプライン
DirectShow.NET — カスタムフィルターグラフ(移行前)
C#// Building a custom graph: source > resize > overlay > encode > mux > write
// Each step requires finding/creating a filter, adding to graph,
// connecting pins with compatible media types
var graphBuilder = (IGraphBuilder)new FilterGraph();
// Add source filter...
// Add resize filter (must find one that's installed)...
// Add overlay filter (must write custom or find one)...
// Add H.264 encoder (system-dependent)...
// Add MP4 mux (system-dependent)...
// Add file writer...
// Connect each pair of pins manually...
// Handle format negotiation failures...
// Total: 150-300 lines, fragile, system-dependentVisioForge Media Blocks — カスタムパイプライン(移行後)
C#var pipeline = new MediaBlocksPipeline();
var source = new SystemVideoSourceBlock(
new VideoCaptureDeviceSourceSettings(device));
var resize = new ResizeBlock(1920, 1080);
var overlay = new TextOverlayBlock("Recording...");
var encoder = new H264EncoderBlock();
var sink = new MP4SinkBlock("output.mp4");
pipeline.Connect(source.Output, resize.Input);
pipeline.Connect(resize.Output, overlay.Input);
pipeline.Connect(overlay.Output, encoder.Input);
pipeline.Connect(encoder.Output, sink.Input);
await pipeline.StartAsync();移行チェックリスト
- DirectShow.NET の使用状況を監査 — すべての `using DirectShowLib` 参照を見つける
- フィルターグラフの目的を特定 — キャプチャ、再生、トランスコーディング、またはカスタム処理
- VisioForge SDK を選択 — Video Capture、Media Player、Video Edit、または Media Blocks
- NuGet パッケージをインストール — DirectShowLib NuGet を VisioForge パッケージに置き換え
- フィルターグラフコードを置き換え
- COM クリーンアップコードを削除 — VisioForge は `IAsyncDisposable` を使用
- サードパーティ DirectShow フィルター依存関係を削除 — VisioForge にはコーデックが含まれる
- モダン .NET をターゲット — .NET 6-10
- クロスプラットフォームテスト
- DirectShow フィルター登録を削除 — 不要に
移行後に得られるもの
| 項目 | DirectShow.NET | 移行後 |
|---|---|---|
| コード行数 | 機能あたり100行以上 | 機能あたり5-10行 |
| フレームワーク | .NET Framework 2.0 | .NET 6-10 |
| プラットフォーム | Windows のみ | Windows、macOS、Linux、iOS、Android |
| API スタイル | 生の COM、手動ピン接続 | 型付き async C# API |
| コーデック | DirectShow フィルターを探してインストール | 内蔵(H.264、H.265、AV1、VP9) |
| メモリ管理 | 手動 `Marshal.ReleaseComObject` | `IAsyncDisposable` |
| デバッグ | 不透明な COM エラー(HRESULT) | 型付き例外、イベント |
| ビデオエフェクト | エフェクトフィルターを探す必要あり | 40+ 内蔵(GPU + CPU) |
| オーディオエフェクト | なし | 40+(EQ、リバーブ、コーラス、3D) |
| ストリーミング | 利用不可 | RTMP、HLS、SRT、NDI |
| 検出 | 利用不可 | 動体(MOG2)、顔(Haar/DNN/DLib)、歩行者(HOG+SVM)、バーコード |
| ハードウェアエンコーディング | エンコーダーフィルターを探す必要あり | NVENC、QSV、AMF、VideoToolbox |
| IP カメラ | 手動フィルターグラフ | RTSP、RTMP、HLS、ONVIF(自動再接続付き) |
| メンテナンス | 放棄(2010年) | 活発な開発 |
Frequently Asked Questions
DirectShow.NET はまだメンテナンスされていますか?
いいえ。DirectShow.NET は2010年2月以降放棄されています。Microsoft も基盤となる DirectShow API を Media Foundation に置き換えて非推奨にしています。
C# ビデオキャプチャに最適な DirectShow.NET の代替は何ですか?
VisioForge Video Capture SDK .Net は DirectShow フィルターグラフを型付き async API に置き換えます。80行以上の COM インターロップが必要だったウェブカメラキャプチャが5行の C# コードになり、内蔵の録画、ハードウェアエンコーディング、クロスプラットフォームサポートを提供します。
VisioForge はカスタム DirectShow フィルターグラフを置き換えられますか?
はい。VisioForge Media Blocks SDK は、カスタムフィルターグラフ構築を置き換える400以上のブロックを持つモジュラーパイプラインを提供します。
VisioForge は .NET 6、.NET 8、.NET 9、.NET 10 をサポートしていますか?
はい。すべての VisioForge .Net SDK パッケージは .NET 6 から .NET 10 をサポートしており、クロスプラットフォームデプロイメントも含まれます。
システムに DirectShow フィルターをインストールする必要はありますか?
いいえ。VisioForge は独自のコーデックとデコーダーをバンドルしています。H.264、H.265、AV1、VP9、AAC などのコーデックがすぐに使えます。
DirectShow.NET から段階的に移行できますか?
はい。VisioForge SDK は同じプロジェクト内で DirectShow.NET と共存できます。フィルターグラフを一つずつ置き換えてください。
