将嵌入的视频资源作为流播放

发布于 2024-11-18 18:35:41 字数 206 浏览 1 评论 0原文

编辑:我改变了我的问题以更好地澄清问题。 如何使用 DirectShow.Net 库播放字节数组(取自嵌入式资源)中的视频?

由于我要阻止用户访问视频文件,因此我需要将视频文件作为资源嵌入并播放。

提前致谢。

EDIT: I changed my question to better clarify the issue.
How is it possible to play a video from a byte array (taken from embedded resource) using DirectShow.Net library?

Since I'm going to prevent users from accessing the video file, I need to embed the video file as resource and play it.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事和酒 2024-11-25 18:35:41

这有点不标准,但您可以使用 WCF 之类的东西在桌面应用程序中自托管端点。然后将视频输入源设置为您的自托管端点的“URL”。这适用于 WPF 或 WinForms。但不确定 Silverlight。

自托管端点可以从嵌入式资源中提取媒体并从那里进行流式传输。

It's a bit non-standard, but you could use something like WCF to self-host an endpoint inside your desktop application. Then set the source of the video input to be the "URL" to your self-hosted endpoint. That would work for WPF or WinForms. Not sure about Silverlight though.

The self-hosted endpoint could pull the media from your embedded resources and stream it from there.

阳光的暖冬 2024-11-25 18:35:41

在我看来,问题不在于如何使用 DirectShow 库(`DirectShow .Net Forum 是专门为此设计的),而是如何使用嵌入式资源。

几年前,我在一份合同工作中遇到了类似的情况,雇主担心某些客户可能会窃取他的专有信息。我的信息存在于数百个 PDF 文档中,但这个想法对于视频文件也是一样的。

以下是我解决问题的方法:

  • 首先,将视频文件放入资源列表中:我使用 Visual Studio,因此我转到项目 的属性,单击资源选项卡,选择文件选项,然后选择添加资源 > 添加现有文件...

  • 将以下两个命名空间添加到您将使用的代码文件中:

使用 System.IO;
使用系统诊断;
  • 最后,在您想要播放视频文件的地方,只需执行类似于以下操作:
 处理player = null;
 字符串 tempFile = "~clip000.dat";
 尝试 {
   File.WriteAllBytes(tempFile, Properties.Resources.MyMovie_AVI);
   播放器= Process.Start(tempFile);
   玩家.WaitForExit();
 } 最后 {
   文件.删除(临时文件);
 }

最有可能的是,您将调用Process.Start方法,而是调用适当的DirectShow方法。想法仍然是一样的:将资源提取为字节数组,将它们写入新的临时文件,使用该文件,然后在任何时候删除该文件完成。

请务必将 Delete 语句放在 finally 块中,以便在发生任何错误或用户在文件仍在运行时关闭程序播放时,您的应用程序仍然会清理旧文件。

编辑:

我认为这可能是一种可行的方法:

using (MemoryStream ms = new MemoryStream(Properties.Resources.MyMovie_AVI)) {
  // Now you have to find a way in `DirectShow` to use a Stream
}

It sounds to me like the problem is not so much how to use the DirectShow library (the `DirectShow.Net Forum is specifically designed for that), but rather how to use an embedded resource.

I ran into something similar a few years back on a contract job where an employer was worried that some customer might steal his proprietary information. My information was in hundreds of PDF documents, but the idea works the same for video files.

Here's how I tackled the problem:

  • First, place the video file in your list of resources: I use Visual Studio, so I go to the Project's Properties, click the Resources tab, select the Files option, then select Add Resource > Add Existing File...

  • Add the following two namespaces to the code file you will be using:

using System.IO;
using System.Diagnostics;
  • Finally, where you want to play your video file, just do something similar to the following:
 Process player = null;
 string tempFile = "~clip000.dat";
 try {
   File.WriteAllBytes(tempFile, Properties.Resources.MyMovie_AVI);
   player = Process.Start(tempFile);
   player.WaitForExit();
 } finally {
   File.Delete(tempFile);
 }

Most likely, you will not be calling the Process.Start method, but rather the appropriate DirectShow method. The idea is still the same: Extract your resources as a byte array, write them to a new, temporary file, use the file, then delete that file whenever you are done.

Be sure to put the Delete statement in the finally block so that if any errors occur or your user closes the program while the file is still playing, your application still cleans up the old file.

EDIT:

I think this might be a viable way of doing this:

using (MemoryStream ms = new MemoryStream(Properties.Resources.MyMovie_AVI)) {
  // Now you have to find a way in `DirectShow` to use a Stream
}
提笔落墨 2024-11-25 18:35:41

你可以使用不同的库吗?

我使用 WPF MediaKit 对安全的实时 h264 视频流进行一些非标准流式传输。开发人员(Jermiah Morill)反应非常灵敏,我可以执行的定制非常广泛(因为您获得了源代码)。

此时,您可以将视频作为嵌入式资源嵌入,将字节数组(可能是一次的一部分或整个文件)加载到内存中,然后从内存中播放。

Can you use a different library?

I used the WPF MediaKit to do some non-standard streaming of a secure, live h264 video stream. The developer (Jermiah Morill) was very responsive, and the customization I could perform was extensive (since you get the source).

At that point, you could embed the video as an embedded resource, load the byte array (perhaps either part of it at a time or the entire file) into memory, and play from memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文