我的网站正在使用ffmpeg为每个上传的视频生成一个缩略图jpg。守则如下:
// get the videos uploaded
foreach ($videos as $video) {
if ($profile_author_id == $userid || current_user_can('level_10')) {
$imagebuttons = '<span class="edit-buttons"><span class="icon button-delete icon-cancel rad3"></span></span>';
}
echo '<div class="profile-video-thumb-wrapper"><div class="profile-img-thumb profile-video-thumb rad3" id="'.$video->ID.'" style="background: url('.$video->guid.'.jpg) center no-repeat; background-size: cover;">';
echo $imagebuttons;
if(get_post_meta($video->ID, 'processing', true) && !is_video_processing_running(get_post_meta($video->ID, 'processing', true))) {
delete_post_meta($video->ID, 'processing');
unlink(get_post_meta($video->ID, "original_file", true));
delete_post_meta($video->ID, 'original_file');
}
$file_path = get_attached_file($video->ID);
$file_path_thumb = $file_path.".jpg";
if(!file_exists($file_path_thumb)) {
$output = shell_exec("/usr/local/bin/ffmpeg -i $file_path");
$videoresizeheight = get_option("videoresizeheight") ? get_option("videoresizeheight") : '400';
$comd = "/usr/local/bin/ffmpeg -y -i \"$file_path\" -f mjpeg -vframes 1 -ss 00:00:03.000 -vf scale=".$videoresizeheight.":-1 \"$file_path_thumb\" 2>&1";
shell_exec($comd);
}
if(get_post_meta($video->ID, 'processing', true)) {
if ($profile_author_id == $userid || current_user_can('level_10')) {
echo '<span class="video-processing rad3">'._d('this video is still processing',1269).'</span>';
echo '<img data-original-url="'.get_template_directory_uri().'/i/video-placeholder.svg" class="mobile-ready-img rad3" alt="'.get_the_title().'" data-responsive-img-url="'.get_template_directory_uri().'/i/video-placeholder-mobile.svg" />';
}
} else {
echo '<div id="'.preg_replace("/([^a-zA-Z0-9])/", "", $video->post_title).'" class="video-player-lightbox text-center hide" itemprop="video" itemscope itemtype="http://schema.org/VideoObject">';
echo '<meta itemprop="thumbnailUrl" content="'.$video->guid.'.jpg" />';
echo '<meta itemprop="contentURL" content="'.$video->guid.'" />';
echo '<video height="100%" width="100%" controls>';
echo '<source src="'.$video->guid.'" type="video/mp4">';
echo _d("Your browser does not support the video tag.",1270);
echo '</video> ';
echo '</div>';
echo '<a href="#'.preg_replace("/([^a-zA-Z0-9])/", "", $video->post_title).'" rel="profile-video">';
echo '<img src="'.$video->guid.'.jpg" class="hide" />';
echo '<img src="'.get_template_directory_uri().'/i/video-placeholder.svg" class="video-image-play" />';
echo '</a>';
}
echo '<div class="clear"></div></div></div>'."\n";
}
if(count($videos) > 0) {
echo '<div class="clear10"></div>';
}这将为每个上传的视频生成一个缩略图jpg文件;但是当jpg的文件名包含从原始视频文件中提取的一个点时(例如,我用文件名video.mp4上传一个视频,这将生成一个jpg文件调用视频.mp4.jpg),就会出现问题。而这个,我的网站会把这个文件当作不存在的。
现在,我需要找到一个解决方案,可以生成正确的缩略图文件名,同时仍然坚持使用wordpress标记,在添加额外的.mp4扩展时,它将-mp4更改为.jpg。
发布于 2019-03-23 09:14:12
在解决方案上工作了两天之后,终于找到了我的用法的解决方案,非常适合我的
在$file_path_thumb,我用
dirname($file_path).'/'.preg_replace("/\./","-",basename($file_path)).".jpg";所以它变成了
$file_path_thumb = dirname($file_path).'/'.preg_replace("/\./","-",basename($file_path)).".jpg";这将只允许在不同的视频扩展名中替换从原始视频文件中提取的额外点。
之后,更改缩略图显示链接的其余部分
"'.$video->guid.'.jpg"至
"'.dirname($video->guid).'/'.preg_replace("/\./","-",basename($video->guid)).'.jpg"示例:我正在上传一个带有文件名somevideo.mp4的视频,这样就不会使用ffmpeg来处理原始文件,同时生成一个缩略图到某个视频-mp4.jpg,然后让显示缩略图指向正确生成的jpg文件。
https://stackoverflow.com/questions/55223742
复制相似问题