如何从 mp4、m3u8 或任何其他文件获取视频时长 [英] How to get video duration from mp4,m3u8 or any other file

查看:80
本文介绍了如何从 mp4、m3u8 或任何其他文件获取视频时长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 NReco.VideoInfo 库是最佳选择且更简单

I found the NReco.VideoInfo library to be the best option and simpler

1] 在 NuGet 包管理器中找到 NReco.VideoInfo 库并将其导入到您的项目中

1] Find the NReco.VideoInfo library in NuGet Package Manager and import it in your project

2] 然后导入命名空间 "using NReco.VideoInfo"

2] After that import the namespace "using NReco.VideoInfo"

3] 将以下代码行添加到方法中.

3] Add the below line of code into the method.

var ffProbe = new FFProbe();
var videoInfo = ffProbe.GetMediaInfo(blob.Uri.AbsoluteUri);
return videoInfo.Duration.TotalMilliseconds;

这里查看其他选项

推荐答案

为什么不使用windows media player来解决这个问题?

Why don't you use the windows media player to solve this problem?

using WMPLib;

public Double getDuration(String path)
{
    WindowsMediaPlayer wmp = new WindowsMediaPlayerClass();
    IWMPMedia mediaInfo = wmp.newMedia(file);
    return mediaInfo.duration;
}

这篇关于如何从 mp4、m3u8 或任何其他文件获取视频时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆