简体   繁体   English

FFMPEG和PHP的视频缩略图

[英]Thumbnail of video with FFMPEG and PHP

I'm creating thumbnail with phpcode: 我正在用phpcode创建缩略图:

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

Instead of a output file I prefer to get a base64 variable. 除了输出文件,我更喜欢获取base64变量。

What is the best to do that? 最好的办法是什么?

Example way: 示例方式:

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

  2. Get file base64 with type, something like: 获取具有类型的文件base64,例如:

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

  3. Delete file 删除文件

My way: 我的方式:

$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