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

查看:306
本文介绍了使用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天全站免登陆