将嵌入的视频资源作为流播放
编辑:我改变了我的问题以更好地澄清问题。 如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有点不标准,但您可以使用 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.
在我看来,问题不在于如何使用 DirectShow 库(`DirectShow .Net Forum 是专门为此设计的),而是如何使用嵌入式资源。
几年前,我在一份合同工作中遇到了类似的情况,雇主担心某些客户可能会窃取他的专有信息。我的信息存在于数百个 PDF 文档中,但这个想法对于视频文件也是一样的。
以下是我解决问题的方法:
首先,将视频文件放入资源列表中:我使用
Visual Studio
,因此我转到项目
的属性,单击资源选项卡,选择文件选项,然后选择添加资源
>添加现有文件...
将以下两个
命名空间
添加到您将使用的代码文件中:最有可能的是,您将不调用
Process.Start
方法,而是调用适当的DirectShow
方法。想法仍然是一样的:将资源提取为字节
数组,将它们写入新的临时文件,使用该文件,然后在任何时候删除该文件完成。请务必将
Delete
语句放在finally
块中,以便在发生任何错误或用户在文件仍在运行时关闭程序播放时,您的应用程序仍然会清理旧文件。编辑:
我认为这可能是一种可行的方法:
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 theProject
's Properties, click the Resources tab, select the Files option, then selectAdd Resource
>Add Existing File...
Add the following two
namespaces
to the code file you will be using:Most likely, you will not be calling the
Process.Start
method, but rather the appropriateDirectShow
method. The idea is still the same: Extract your resources as abyte
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 thefinally
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:
你可以使用不同的库吗?
我使用 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.