gpt4 book ai didi

php - 如何从 mp4 文件生成图像?

转载 作者:行者123 更新时间:2023-12-04 23:17:19 25 4
gpt4 key购买 nike

我正在尝试生成 images来自 mp4带有 ffmpeg 的视频文件.

我只想要文件中每个视频的前 3 秒。

我有以下命令..

 $videoFile = $mp4File; //I have many mp4 files

$ffmpeg ="/usr/ffmpeg";

$image_path = $videoFile;

$ALL_PLACE_WIDTH = 300;
$ALL_PLACE_HEIGHT = 220;

$image_cmd = " -r 1 -r 0.03 -s ".$ALL_PLACE_WIDTH."x".$ALL_PLACE_HEIGHT." -f image2 ";
$dest_path = 'project/image-%01d.png';

$str_command= $ffmpeg ." -i " . $image_path . $image_cmd .$dest_path;
shell_exec($str_command);

我正在尝试生成每个 mp4 的前 3 秒图像文件,但我的脚本会生成很多图像,它会在整个 mp4 中创建图像文件。

我可以限制脚本只获取前 3 秒的图像吗?非常感谢!

最佳答案

如果我理解正确,您需要三秒钟内的一张图像。

改变:

$image_cmd = " -r 1 -r 0.03 -s ".$ALL_PLACE_WIDTH."x".$ALL_PLACE_HEIGHT." -f image2 ";

至:
$image_cmd = " -vf scale=".$ALL_PLACE_WIDTH.":-1 -frames:v 1 -ss 3 ";

有什么不同?
  • -r-f image2不是必需的。
  • scale filter可以用-1自动调整高度或宽度相对于您的给定值,因此保留了方面。这避免了绝对调整大小可能导致的拉伸(stretch)或挤压。这意味着 $ALL_PLACE_HEIGHT = 220;不需要。
  • 使用-frames:v 1输出一帧。
  • -ss是偏移时间,或您想要图像的时间。
  • 关于php - 如何从 mp4 文件生成图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16703480/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com