2
using Microsoft.DirectX.AudioVideoPlayback;

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

「インストールされたアプリケーションドメインへのアクセスが試行されました。」</p>

「vvideo」インスタンスが作成されましたエラーmsj://

しかし、ダウンが見つかったコードは、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

私はそれが使用するすべての場所で関数を作成します;)

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

プロジェクトに2つの名前空間を追加します

Microsoft.WindowsAPICodePack.Shellを使用します。using.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

ffprobeAlturos.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 に答える