如何转换上传的视频并从此文件获取屏幕截图?

发布于 2024-08-29 20:27:32 字数 172 浏览 2 评论 0原文

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

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

谢谢

I'm building a cms and I want users to be able to upload videos but I'm not familiar with video upload & conversion. Is there an example or has anybody coded a solution like this?
I heard about ffmpeg but I don't know how to integrate it with asp.net.

As simple solution I can make my clients upload flv files but then I would still need to get a screenshot from that fvl.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慵挽 2024-09-05 20:27:32

回答作者的问题:

是否需要安装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);

Answering author's question:

Does ffmpeg requires to be installed
server side or just exe is enough?

ffmpeg.exe will be enough, no installation is required.

The code below gets a screenshot on captureTime on video specified by videoFilename variable, and saves it to the imageFilename path.

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);
烙印 2024-09-05 20:27:32

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

I've used ffmpeg, but I found it easier to just use the pre-compiled .exe version. So in the backend, I would just launch ffmpeg.exe with the required command-line arguments to do the conversion, let it run and when it was finished the completed file was all ready to go.

丑疤怪 2024-09-05 20:27:32

很久很久以前,在我的 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 参数给出。当然,请确保给定位置对于执行用户是可写的。

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

A long, long time ago in my PHP4 days I used the following method, calling ffmpeg on the shell and creating a screenshot.

/**
 * 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}");
}

It takes a supported video file as $sourcefile. The desired file location for the screenshot can be given by the $destfile parameter. Off course make sure that the given location is writeable for the executing user.

Hopefully this is also usable for anyone else who's looking for the right syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文