【问题标题】:How to convert uploaded video and get a screenshot from this file?如何转换上传的视频并从此文件中获取屏幕截图?
【发布时间】:2011-02-10 13:17:48
【问题描述】:

我正在构建一个 cms,我希望用户能够上传视频,但我不熟悉视频上传和转换。是否有示例或有人编写过这样的解决方案? 我听说过 ffmpeg,但我不知道如何将它与 asp.net 集成。

作为简单的解决方案,我可以让我的客户上传 flv 文件,但我仍然需要从该 fvl 获取屏幕截图。

谢谢

【问题讨论】:

    标签: asp.net flash flv video-processing video-encoding


    【解决方案1】:

    回答作者的问题:

    ffmpeg 是否需要安装 服务器端还是只用exe就够了?

    ffmpeg.exe就足够了,不需要安装。

    下面的代码在videoFilename变量指定的视频上获取captureTime的屏幕截图,并将其保存到imageFilename路径。

    Process ffmpeg = new Process();
    ffmpeg.EnableRaisingEvents = true;
    ffmpeg.StartInfo = new ProcessStartInfo
    {
        FileName = this.ffmpegPath,
        Arguments = string.Format(
            "-i \"{0}\" -an -y -s 320x240 -ss {1} -vframes 1 -f image2 \"{2}\"",
            this.videoFilename,
            DateTime.MinValue.Add(this.captureTime).ToString("HH:mm:ss:ff", CultureInfo.InvariantCulture),
            this.imageFilename
        ),
        WorkingDirectory = this.workingDirectory,
        UseShellExecute = false,
        RedirectStandardError = true,
        RedirectStandardOutput = true,
        WindowStyle = ProcessWindowStyle.Hidden
    };
    
    ffmpeg.Start();
    ffmpeg.WaitForExit(this.timeout);
    

    【讨论】:

    • @Alex:我无法在本地主机上使用 Asp.net,但该命令运行良好:C:\inetpub\wwwroot\ffmpeg.exe -i "c:\inetpub\wwwroot \test.flv" -an -y -s 320x240 -ss 00:00:03:00 -vframes 1 -f image2 "c:\inetpub\wwwroot\test.jpg"
    • @HasanGursoy:ASP.NET 有什么问题?也许这是安全问题?
    • 没错。没有错误,所以我无法调试。输出目录必须有写权限。
    【解决方案2】:

    我使用过 ffmpeg,但我发现使用预编译的 .exe 版本更容易。所以在后端,我只需使用所需的命令行参数启动 ffmpeg.exe 来进行转换,让它运行,完成后,完成的文件就准备好了。

    【讨论】:

    • @codeka:你能发布示例命令吗? ffmpeg 需要在服务器端安装还是只需要安装 exe 就足够了?因为如果够的话我会把它放在 bin 文件夹中。
    • 我从:ffmpeg.arrozcru.org 下载了 exe,命令行非常简单,并且在此处有很好的记录:ffmpeg.org/ffmpeg-doc.html
    【解决方案3】:

    很久很久以前,在我 PHP4 的日子里,我使用了以下方法,在 shell 上调用 ffmpeg 并创建一个屏幕截图。

    /**
     * Create a snapshot of a videofile and save it in jpeg format
     */
    function snapshot($sourcefile,$destfile,$width=184,$height=138,$time=1){
        $width=floor(($width)/2)*2;
        $height=floor(($height)/2)*2;
        exec("ffmpeg -i {$sourcefile} -s {$width}x{$height} -t 0.0001 -ss {$time} -f mjpeg {$destfile}");
    }
    

    它将支持的视频文件作为 $sourcefile。屏幕截图所需的文件位置可以由 $destfile 参数给出。当然,请确保给定位置对于执行用户是可写的。

    希望这对正在寻找正确语法的其他人也有用。

    【讨论】:

    • 你在帖子的任何地方都看到了 php 标签吗?还是谢谢你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2018-09-28
    • 1970-01-01
    相关资源
    最近更新 更多