简体   繁体   English

如何在C#(通用Windows应用)中以编程方式获取视频时长/时长?

[英]How to get video length / duration programatically in C# (Universal windows apps)?

I've searched about this for a while, and most answers seem to suggest using the directshow library, which I've tried, but it didn't work. 我已经搜索了一段时间,大多数答案似乎都建议使用DirectShow库,该库我已经尝试过了,但是没有用。 My program currently works on selecting a video file using the FileOpenPicker, then checks its length and uploads it to the cloud if it's below a certain length. 我的程序当前正在使用FileOpenPicker选择视频文件,然后检查其长度,如果长度不足则将其上传到云中。 Please keep in mind that this needs to work for Universal Windows Apps. 请记住,这需要适用于Universal Windows Apps。

You can use DirectShow API MediaDet object, through DirectShow.NET wrapper library. 您可以通过DirectShow.NET包装器库使用DirectShow API MediaDet对象。 See Getting length of video for code sample, get_StreamLength gets you the duration in seconds. 请参阅获取视频长度以获取代码示例, get_StreamLength可以获取持续时间(以秒为单位)。 This assumes Windows has MPEG-4 demultiplexer installed (requires third party components with Windows prior to 7, I believe the same applies to another answer by cezor , there are free to redistribute components though).You can use DirectShow API MediaDet object, through DirectShow.NET wrapper library. 假设Windows已安装MPEG-4解复用器(Windows 7之前需要使用Windows的第三方组件,我相信cezor的另一个答案也是如此 ,不过可以随意重新分发组件)。您可以通过DirectShow使用DirectShow API MediaDet对象。 .NET包装器库。 See Getting length of video for code sample, get_StreamLength gets you the duration in seconds. 请参阅获取视频长度以获取代码示例, get_StreamLength可以获取持续时间(以秒为单位)。 This assumes Windows has MPEG-4 demultiplexer installed (requires third party components with Windows prior to 7, I believe the same applies to another answer by cezor , there are free to redistribute components though). 假定Windows已安装MPEG-4多路分解器(Windows 7之前需要使用Windows的第三方组件,我相信cezor的另一答案也是如此 ,不过可以自由地重新分发组件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在C#中获取视频文件的持续时间 - how to get video file duration in C# 如何在C#Windows Universal Apps中将字符串附加到文本文件中 - How to append a string into a text file in C# Windows Universal Apps 在Windows通用应用程序C中流式传输图像 - streaming images in windows universal apps c# C# - 在通用应用程序中获取 mac 地址 - C# - Get mac address in Universal Apps 如何获得视频时长? ASP.NET MVC 5 C# - How to get the video duration ? ASP.NET MVC 5 C# C#通用Windows应用程序如何从互联网获取时间 - C# Universal Windows Application How to get time from internet 压缩或压缩文件-Windows Phone通用应用程序-C# - Compress or Zip a File - Windows Phone Universal Apps - C# 使用C#在通用Windows应用程序中未检测到键盘布局更改 - Keyboard layout change not detected in universal windows apps with C# 通用Windows平台(UWP)应用程序的C#服务器/客户端应用程序 - C# Server / Client Application for Universal Windows Platform (UWP) apps 如何使用Windows Universal Apps(C#,XAML)存储数据/使用数据库 - How to store data / use databases with Windows Universal Apps (C#, XAML)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM