用于创建视频缩略图的 WCF 服务

发布于 2024-07-11 13:51:35 字数 249 浏览 1 评论 0原文

我正在尝试创建一个 WCF 服务,该服务利用服务器上的 WPF MediaPlayer 为用户上传的视频生成缩略图。 我发现了很多关于如何渲染帧并将其保存到文件的 oif 信息。 但问题是关键事件 MediaOpened (实际上没有任何事件)我需要绑定到 doesn't - 编辑火。

有谁知道如果在 WCF 服务的上下文中使用 WPF MediaPlayer 事件是否不会触发?

谢谢 迈克尔

I am trying create a WCF service that leverages the WPF MediaPlayer on the server to generate thumbnails for a video that a user uploads. I found a lot oif info on how to render a frame and save it to a file. But the problem is the key event MediaOpened (actually none of the events) I need to tie into doesn't - EDIT fire.

Does anyone know if the WPF MediaPlayer events do not fire if used ion the context of a WCF service?

thanks
Michael

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

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

发布评论

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

评论(2

命比纸薄 2024-07-18 13:51:35

我决定尝试使用 Expression Media Encoder 2 SDK,效果非常好。

从视频生成缩略图的代码非常少 - 这是一个片段

public void GenerateThumbnails(string fileName, int numberOfThumbnails)

{
队列_positionsToThumbnail = new Queue();
Microsoft.Expression.Encoder.MediaItem 视频 = new Microsoft.Expression.Encoder.MediaItem(fileName);

var totalMilliseconds = video.FileDuration.TotalMilliseconds;

//create a queue of timespans for the thumbnails
for (int i = 0; i < numberOfThumbnails; i++)
{
    _positionsToThumbnail.Enqueue(TimeSpan.FromMilliseconds((((2 * i) + 1) * totalMilliseconds) / (2 * numberOfThumbnails)));
}

//create the thumbnails and save them to disk
while(_positionsToThumbnail.Count > 0)
{

    Bitmap bitMap = video.GetThumbnail(_positionsToThumbnail.Dequeue(), new System.Drawing.Size(100,100));
    bitMap.Save(@"F:\thumbs\" + _positionsToThumbnail.Count.ToString() + ".png", ImageFormat.Png);
}

}

I decided to try and use the Expression Media Encoder 2 SDK and it worked great.

Very little code to generate thumbnails from a video - here is a snippet

public void GenerateThumbnails(string fileName, int numberOfThumbnails)

{
Queue _positionsToThumbnail = new Queue();
Microsoft.Expression.Encoder.MediaItem video = new Microsoft.Expression.Encoder.MediaItem(fileName);

var totalMilliseconds = video.FileDuration.TotalMilliseconds;

//create a queue of timespans for the thumbnails
for (int i = 0; i < numberOfThumbnails; i++)
{
    _positionsToThumbnail.Enqueue(TimeSpan.FromMilliseconds((((2 * i) + 1) * totalMilliseconds) / (2 * numberOfThumbnails)));
}

//create the thumbnails and save them to disk
while(_positionsToThumbnail.Count > 0)
{

    Bitmap bitMap = video.GetThumbnail(_positionsToThumbnail.Dequeue(), new System.Drawing.Size(100,100));
    bitMap.Save(@"F:\thumbs\" + _positionsToThumbnail.Count.ToString() + ".png", ImageFormat.Png);
}

}

夢归不見 2024-07-18 13:51:35

您可能需要在屏幕上呈现数据,以便触发这些事件——这一切都与 WPF 可视化树的一部分相关; 当作为服务运行时则不然。

您可以尝试多种方法来解决此问题,但所有这些方法都很复杂,而且可能无法扩展。 我建议使用普通的 Windows Media API(来自 Windows Media SDK)来深入了解它。

You will likely need to render the data on screen, for those events to be fired -- it's all tied to being part of the WPF visual tree; which when running as a service it is not.

There are many ways you could try to resolve this, all of which are convoluted, and likely not going to scale. I suggest using the normal windows media API's (from the Windows Media SDK) to get to the bottom of it.

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