获取视频长度
我无法找到一个简单的示例来说明如何以编程方式获取文件的视频长度。很多人说,哦,使用这个库/包装器或其他什么,但没有说如何使用。我已经下载了 ffmpeg,但不知道如何实际使用它,并且似乎没有任何示例说明如何使用它来获取视频时长。我了解如何使用它来转换视频,但我只是想知道视频的持续时间。所有其他信息都不重要。
有什么方法可以简单地做到这一点,无论是 C#、Python、Java 还是其他语言,都只会返回一个指示视频文件长度的字符串。
如果可能,请提供示例。提前致谢!
假设标准文件格式,例如 wmv、avi、mp4、mpeg。具有元数据的东西。
I am having trouble finding a simple example of how to get the video length of a file programmatically. Many people say, oh use this library/wrapper or whatever, but do not say how. I have downloaded ffmpeg, but have no clue how to actually use it and there does not seem to be any example of how to use it to get the video duration. I see how you can use it to convert videos, but I simply just want to know the duration of a video. All of the other information does not matter.
Is there any way of doing this simply, whether it be in C#, python, java, whatever, that will just return a string that indicates the length of a video file.
Please provide examples if possible. Thanks in advance!
Assume standard file formats, such as wmv, avi, mp4, mpeg. Stuff that has metadata.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
这是一个例子:
Here is an example:
我发现的简单且完美的解决方案是使用 MediaToolkit nuget 包。
The easist and flawless solution I found is to use MediaToolkit nuget package.
开源工具 MediaInfo 提供媒体文件的全面元数据,可以使用 轻松从您自己的应用程序以 DLL 形式:
The open-source tool MediaInfo provides comprehensive meta-data for media files and can be used easily from your own application in DLL form:
我尝试以一种不同的方式获取视频长度:
实际上也使用 Windows Media Player 组件,我们可以获得视频的持续时间。
以下代码片段可能对你们有帮助:
I have tried to get the video length in a bit different way :
Actually using Windows Media Player Component also, we can get the duration of the video.
Following code snippet may help you guys :
您可以使用 -i 标志获取有关多种类型的视频格式的各种信息,包括它们在 ffmpeg 中的持续时间:
如果您想要一个可以在 C# 中为您包装 ffmpef 的漂亮库,那么您可以使用 MediaHandlerPro
you can get all sorts of information about many types of video formats including their duration with ffmpeg by using the -i flag:
If you want a nice library that can wrap ffmpef for you in C# then you can use MediaHandlerPro
ffprobe 是 ffmpeg 项目的配套工具。除了提供各种文件格式的信息外,它还可以以 JSON 格式输出以简化解析。
查看此答案以获取 JSON 输出的示例。
ffprobe is companian tool from the ffmpeg project. Besides provinding information from a wide range of file formats, it can also ouput in a JSON format to ease the parsing.
Check this answer for an example of a JSON output.
我最近找到了一个类似问题的解决方案,使用 ColdFusion 和 FFMpeg 的小表弟 FFProbe...
有没有办法使用 ColdFusion 获取视频文件的持续时间?
FFProbe 有一个 show_streams 参数,可以推出大量的返回输出中初始流中的信息;包括视频的宽度、高度和持续时间...
不确定运行“ffprobe.exe -show_streams testFile”等价物的 C# 语法,但我确信一旦你弄清楚了这一点,你就可以解析出信息您需要从收到的输出中获取。
I recently found a solution to a similar problem I had, with ColdFusion and FFMpeg's little cousin, FFProbe...
Is there a way to obtain the duration of a video file using ColdFusion?
FFProbe has a show_streams argument that pushes out a considerable amount of information in the initial stream within the returned output; including the width, height and duration of a video...
Not sure about C#'s syntax for running the equivalent of "ffprobe.exe -show_streams testFile" but I'm sure once you've figured that out, you can parse out the information you need from the output you receive.
如果使用 VideoCapture 对象,您可以使用 Emgu.CV 获取大量视频数据:
在这里回复是因为我偶然发现这篇文章寻找相同的东西 - 添加它以防万一它对任何人有帮助。
You can use Emgu.CV to get a lot of video data if using a VideoCapture object:
Responding here because I stumbled across this post looking for the same thing - adding it just in case it helps anyone.
Namaskaram,
最简单的方法之一是使用 OpenCvSharp。它也允许用于商业用途。
Namaskaram,
One of the simplest ways is to use OpenCvSharp. It is allowed for commercial usage as well.