录制视频时,如何更改libVlcSharp中的录像带



我正在尝试使用libVlcSharp将直播视频录制到文件中。该直播流包含两个不同的视频音轨,默认情况下,当我录制文件时,会录制第二个音轨,而不是第一个。奇怪的是,当我播放视频而不是录制时,第一首曲目被选中了。这是我的代码片段:

var id = Guid.NewGuid();
using var libvlc = new LibVLC(enableDebugLogs: true);
var path = Path.Combine(_persistenceSettings.DataPath, id + ".ts");
using var media = new Media(libvlc, new Uri(source));
media.AddOption(":sout=#file{dst=" + path + "}"); // If I remove these two options, then the first track is played. With them, the second track is recorded
media.AddOption("sout-keep");
_mediaPlayer = new MediaPlayer(media);
if (!_mediaPlayer.Play())
{
throw new CameraRecordingException($"Camera {source} could not be initialized");
}
// I know that the second track (the one I don't want) has less than 1000px, whereas the first one is 1920x1080
var track = media.Tracks.FirstOrDefault(t => t.TrackType == TrackType.Video && t.Data.Video.Height > 1000);
_mediaPlayer.SetVideoTrack(track.Id);

在设置了新的VideoTrack id(设置正确,因为我检查了属性_mediaPlayer.VideoTrack并更改了它(后,我还尝试停止并再次播放播放,但没有发生任何事情,录制的视频仍然是第二个音轨。

我也尝试过解析媒体而不是播放它(为了获得曲目,否则曲目列表是空的(,并在SetVideoTrack调用后播放它,但如果我不调用play,曲目列表总是空的,这种方式:

var id = Guid.NewGuid();
using var libvlc = new LibVLC(enableDebugLogs: true);
var path = Path.Combine(_persistenceSettings.DataPath, id + ".ts");
using var media = new Media(libvlc, new Uri(source));
media.AddOption(":sout=#file{dst=" + path + "}"); // If I remove these two options, then the first track is played on a new window. With them, the second track is recorded
media.AddOption("sout-keep");
await media.Parse(MediaParseOptions.ParseNetwork);
while(!media.isParsed) { }
_mediaPlayer = new MediaPlayer(media);
var track = media.Tracks.FirstOrDefault(t => t.TrackType == TrackType.Video && t.Data.Video.Height > 1000); // Here, media.Tracks is empty
_mediaPlayer.SetVideoTrack(track.Id);
if (!_mediaPlayer.Play())
{
throw new CameraRecordingException($"Camera {source} could not be initialized");
}

问题:在开始录制文件之前,如何选择视频曲目?

事实上,我已经检查过视频是用两个视频轨道录制的。问题是,当尝试使用libVlcSharp选择视频音轨时,Id不正确,即:

  • 如果您想更改视频音轨,您需要调用MediaPlayer.SetVideoTrack,并将音轨id作为参数
  • 访问Media.Tracks.Id返回错误的Id(在我的情况下,有两个视频音轨和一个音频音轨,它们的Id分别为0、1和2(,因此在调用SetVideoTrack时,我设置的Id为1
  • 我知道Id是不正确的,因为打开";。ts";使用VLC程序创建文件,然后转到"工具"-->多媒体信息(我认为这是一个选项,我的VLC是西班牙语(->编解码器,您可以看到一个名为";原始Id";。在我的情况下,三条不同的赛道分别为100、101和200。调用Id为101的SetVideoTrack(我想要的(打开了一个新窗口并播放了正确的曲目。这对我来说是另一个问题,而不是重复使用同一个窗口,但这是另一问题

最新更新