繁体   English   中英

FFMPEG和PHP的视频缩略图

[英]Thumbnail of video with FFMPEG and PHP

我正在用phpcode创建缩略图:

$cmd = 'ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png';
echo shell_exec($cmd);

除了输出文件,我更喜欢获取base64变量。

最好的办法是什么?

示例方式:

  1. 将文件保存到任何地方

  2. 获取具有类型的文件base64,例如:

    $ content ='data:'。$ type。'; base64,'。base64_encode(file_get_contents($ url));

  3. 删除文件

我的方式:

$temp_file = tempnam(sys_get_temp_dir(), 'thumbnail_');
rename($temp_file, $temp_file .= '.png');
$cmd = '/usr/local/bin/ffmpeg -y -i '.$url.' -ss 00:00:1 -vframes 1 '.$temp_file.' 2>&1';
shell_exec($cmd );
$content = 'data:'.$type.';base64,'.base64_encode(file_get_contents($temp_file));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM