【问题标题】:ffmpeg generate thumbnail with aspect ratio, but X seconds into videoffmpeg 生成具有纵横比的缩略图,但 X 秒进入视频
【发布时间】:2013-09-24 23:38:24
【问题描述】:

因此,此命令适用于在视频中生成 5 秒的缩略图,大小为 300x300:

$cmd = '/usr/local/bin/ffmpeg -i '.$this->getUploadRootDir().'/'.$fname.' -ss 00:00:05 -f image2 -vframes 1 -s 300x300 '.$this->getUploadRootDir().'/thumb_'.$output;

但是,我想保持纵横比,所以我将代码更改为:

$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:5 -f image2 scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;

上面的代码正确地调整了图像的大小,但是它是视频中第一帧的大小。我需要缩略图为 5 秒。任何帮助将不胜感激。

【问题讨论】:

  • 你没有忘记-filter:v之前的scale吗?
  • @slhck 是的,您应该将其发布为答案。

标签: php ffmpeg


【解决方案1】:

您可以使用类似于以下内容的命令行来执行此操作:

ffmpeg -i inputVideo -vf scale='min(300,iw)':-1 -ss 00:00:05 -f image2 -vframes 1 thumbnail.jpg

因此,在您的脚本中,在缩放之前添加 -vf(视频过滤器)并重新排序输入和输出参数,如下所示:

$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -vf scale='min(300\, iw):-1' -ss 00:00:5 -f image2 -vframes 1 ".$this->getUploadRootDir()."/thumb_".$output;

【讨论】:

    【解决方案2】:

    @alexbuisson 有正确答案,但只是为了确认我今天正在玩 ffmpeg:

    这对我有用:

    ffmpeg -i "my_video.mp4" -ss 00:00:05 -f image2 -vf scale="min(300\, iw):-1" -vframes 1 "capture.jpg"
    

    我得到一张 300 像素宽的 Jpeg,图像比例正确。

    所以适应了你的代码,这变成了:

    $cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:05 -f image2 -vf scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;
    

    【讨论】:

      猜你喜欢
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2013-12-23
      • 2018-12-21
      • 2017-05-26
      • 2012-09-01
      相关资源
      最近更新 更多