使用 FFMpeg 获取视频的中帧? [英] Use FFMpeg to get middle frame of a video?

查看:35
本文介绍了使用 FFMpeg 获取视频的中帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 FFMpeg 来抓取视频的中间帧.我已经编写了 C# 来在特定时间抓取一帧(即在第 3 秒拉一帧).但我还没有弄清楚如何使用 FFMpeg 命令找到视频的中间部分.

I'm wondering how to use FFMpeg to grap the middle frame of a video. I've already written the C# to grab a frame at a certain time (ie pull one frame at second 3). But I've yet to figure out how to find the middle of video using the FFMpeg commands.

推荐答案

这可以简化,但这里有一些我散布的旧 PHP 代码应该可以解决问题.(如果它不在你的路径中,请将位置添加到 ffmpeg)

This could be simplified, but here's some old PHP code I had lying around that should do the trick. (Add the location to ffmpeg if it's not in your path)

$output = shell_exec("ffmpeg -i {$path}");
preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([^ ,])+/', $output, $matches);
$time = str_replace("Duration: ", "", $matches[0]);
$time_breakdown = explode(":", $time);
$total_seconds = round(($time_breakdown[0]*60*60) + ($time_breakdown[1]*60) + $time_breakdown[2]);
shell_exec("ffmpeg -y  -i {$path} -f mjpeg -vframes 1 -ss " . ($total_seconds / 2) . " -s {$w}x{$h} {$output_filename}");   

这篇关于使用 FFMpeg 获取视频的中帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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