在 iThome 舉辦的 iTHelp 2025 鐵人賽當中發表了 "莫名其妙就跟世界等級的 OpenSource 專案攪和了!?" 系列文。
其中 "EP 30 - .NET + AvaloniaUI + GStreamer 跨平台" 裡,有展示了透過 WSL 在 Ubuntu 的環境中使用 GStreamerPlayer 的應用程式 (透過 .NET + Avalonia UI + GStreamer 的技術),來透過 GStreamer 的技術播放影片。

選取播放 Windows 底下的 "C:\Tmp\bbb_sunflower.mp4"。

而在這邊是要在 Ubuntu 直接透過 dotnet GStreamerPlayer.dll 的方式來執行,不透過 Visual Studio 進行 WSL 的偵錯執行。
首先可以先參考一下:
EP 04 - 番外篇 WSL 環境的運作設定
把 .NET 8 runtime 跟 libfontconfig1、libice6、libsm6 這三個套件安裝完成。
這邊直接列 apt 安裝指令:
apt install -y dotnet-runtime-8.0apt install libfontconfig1
apt install libice6
apt install libsm6
在 Visual Studio 也能使用透過工具列 "檢視" → "終端":

直接開啟 "開發者人員 PowerShell",透過 wsl 自由切換是否進入 WSL 環境:


直接在開發人員 PowerShell 中,透過 dotnet publish 指令 "--runtime" 的部分則設定 "linux-x64" 直接發佈; "--configuration" 的部分則設定 "Release":
dotnet publish .\GStreamerPlayer.csproj --runtime linux-x64 --configuration Release
成功

接著進入 wsl 的 Ubuntu 環境當中把發佈的檔案複製到 Ubuntu 的環境中:
cp -r ./bin/Release/net8.0/linux-x64/publish/ ~/GStreamerPlayer
由於沒有指定 output 路徑,就從 publish 預設路徑複製到 Ubuntu 環境當中。
接下來透過另外一個 命令提示字元的終端連入 WSL 的 Ubuntu 環境中。
由於此 WSL 的 Ubuntu 環境 尚未安裝 GStreamer 及其所有的相依套件,所以透過下列 apt-get 安裝:
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev libgstrtspserver-1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
注意,上述指令跟 GStreamer 的官方說明文件中的套件多了 "libgstrtspserver-1.0-dev"。

記得需要有 root 權限才能順利安裝:

繼續嗎?Y (是):

安裝完畢後,透過 "gst-launch-1.0 --version" 指令查詢所安裝的 GStreamer 是否成功:

若可以看到正確回應:
gst-launch-1.0 version 1.24.2
GStreamer 1.24.2
https://launchpad.net/ubuntu/+source/gstreamer1.0恭喜安裝成功。
再次回到 Visual Studio 的 開發人員 PowerShell 當中,直接透過:
dotnet GStreamerPlayer.dll
該 GStreamerPlayer 應用正確執行:

I'm a Microsoft MVP - Developer Technologies (From 2015 ~).

I focus on the following topics: Xamarin Technology, Azure, Mobile DevOps, and Microsoft EM+S.
If you want to know more about them, welcome to my website:
https://jamestsai.tw
本部落格文章之圖片相關後製處理皆透過 Techsmith 公司 所贊助其授權使用之 "Snagit" 與 "Snagit Editor" 軟體製作。