2
using Microsoft.DirectX.AudioVideoPlayback;

Video vvideo = new Video(FileUpload.FileName.ToString());
StringBuilder sb = new StringBuilder();
sb.Append(duration.toString());
error message;

“Installed 对应用程序域进行了访问尝试。”</p>

“vvideo”实例创建错误 msj://

但是下来发现了 cods 我在 c# 中找到了一个工作代码。但 asp.net 不起作用

string file1 = "c://ds.mpeg"
IMediaPosition m_objMediaPosition = null;
FilgraphManager m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(filename);
m_objMediaPosition = m_objFilterGraph as IMediaPosition;

int s = (int)m_objMediaPosition.Duration;
int h = s / 3600;
int m = (s - (h * 3600)) / 60;
s = s - (h * 3600 + m * 60);

我不拍视频男孩:/

4

3 回答 3

1

我在它使用的任何地方都制作 Function ;)

public string f_VideoDuration((add path)parameters)
{

    try
    {
        string sInputVideo = Page.MapPath(add path);
        string sPath = " -i " + sInputVideo ;

        Process ffmepg = new Process();
        ffmepg.StartInfo.FileName = (Server.MapPath("ffmpeg.exe"));
        ffmepg.StartInfo.UseShellExecute = false;
        ffmepg.StartInfo.RedirectStandardOutput = true;
        ffmepg.StartInfo.RedirectStandardError = true;
        ffmepg.StartInfo.CreateNoWindow = true;
        ffmepg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        ffmepg.StartInfo.Arguments = sPath;
        ffmepg.EnableRaisingEvents = true;
        ffmepg.Start();
        string sDuration = ffmepg.StandardError.ReadToEnd().ToString();
        ffmepg.Close();
        ffmepg.Dispose();

        sDuration = sDuration.Remove(0, sDuration.LastIndexOf("Duration: ") + 10);
        sDuration = sDuration.Substring(0, sDuration.IndexOf(","));
        return sDuration;
    }
    catch (Exception ex)
    {
        throw (ex);
    }
}
于 2010-06-14T07:33:38.930 回答
0

首先,我尝试使用 FFMPEG Wrapper,但在找到一个简单的解决方案后出现错误。

你可以使用这个金块包:

Install-Package Microsoft.WindowsAPICodePack-Shell -Version 1.1.0

在您的项目中添加两个命名空间

使用 Microsoft.WindowsAPICodePack.Shell;使用.Microsoft.WindowsAPICodePack.Shell.PropertySystem;

ShellFile so = ShellFile.FromFilePath("your file path");
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out var nanoseconds);

if (nanoseconds > 0)
{
     double seconds = Convert100NanosecondsToMilliseconds(nanoseconds) / 1000;
     int ttl_seconds = Convert.ToInt32(seconds);
     TimeSpan time = TimeSpan.FromSeconds(ttl_seconds);
} 

public static double Convert100NanosecondsToMilliseconds(double nanoseconds)
{           
     return nanoseconds * 0.0001;
}

在这里,我将秒数存储在TimeSpan中,因此它直接给出小时:分钟:秒。

于 2018-08-16T07:39:58.173 回答
0

您可以将我们的包装器用于 ffprobe Alturos.VideoInfo。您只需安装nuget软件包即可使用它。还需要ffprobe二进制文件。

PM> install-package Alturos.VideoInfo

例子

var videoFilePath = "myVideo.mp4";

var videoAnalyer = new VideoAnalyzer("ffprobe.exe");
var analyzeResult = videoAnalyer.GetVideoInfo(videoFilePath);

var duration = analyzeResult.VideoInfo.Format.Duration;
于 2019-06-29T19:38:08.637 回答