오디오가 없는 MP4 동영상만 GIF로 취급 하도록 개선

This commit is contained in:
conory 2019-10-02 14:57:38 +09:00
parent 16e44d44c7
commit ac9141b4f2
3 changed files with 48 additions and 24 deletions

View file

@ -1015,7 +1015,7 @@ class fileController extends file
$args->uploaded_filename = './' . substr($uploaded_filename, strlen(RX_BASEDIR)); $args->uploaded_filename = './' . substr($uploaded_filename, strlen(RX_BASEDIR));
$args->file_size = @filesize($uploaded_filename); $args->file_size = @filesize($uploaded_filename);
// Move the created thumbnail image // Move the generated thumbnail image
if($file_info['thumbnail']) if($file_info['thumbnail'])
{ {
$thumbnail_filename = $storage_path . Rhymix\Framework\Security::getRandom(32, 'hex') . '.jpg'; $thumbnail_filename = $storage_path . Rhymix\Framework\Security::getRandom(32, 'hex') . '.jpg';
@ -1223,8 +1223,11 @@ class fileController extends file
// Generate a thumbnail image // Generate a thumbnail image
if ($result) if ($result)
{ {
$file_info['thumbnail'] = $file_info['tmp_name'] . '.thumbnail.jpg'; $thumbnail_name = $file_info['tmp_name'] . '.thumbnail.jpg';
FileHandler::createImageFile($file_info['tmp_name'], $file_info['thumbnail'], $adjusted['width'], $adjusted['height'], 'jpg'); if (FileHandler::createImageFile($file_info['tmp_name'], $thumbnail_name, $adjusted['width'], $adjusted['height'], 'jpg'))
{
$file_info['thumbnail'] = $thumbnail_name;
}
} }
} }
else else
@ -1258,32 +1261,53 @@ class fileController extends file
return $file_info; return $file_info;
} }
// Generate a thumbnail image // Analyze video file
if ($config->video_thumbnail) $command = $config->ffprobe_command;
$command .= ' -v quiet -print_format json -show_streams';
$command .= ' ' . escapeshellarg($file_info['tmp_name']);
@exec($command, $output, $return_var);
if ($return_var !== 0 || !$output = json_decode(implode('', $output), true))
{ {
$output_name = $file_info['tmp_name'] . '.thumbnail.jpeg'; return $file_info;
}
$command = $config->ffmpeg_command; // Get stream information
$command .= sprintf(' -ss 00:00:00.%d -i %s -vframes 1', mt_rand(0, 99), escapeshellarg($file_info['tmp_name'])); $stream_info = [];
$command .= ' ' . escapeshellarg($output_name); foreach ($output['streams'] as $info)
@exec($command, $output, $return_var); {
$stream_info[$info['codec_type']] = $info;
}
if (empty($stream_info['video']))
{
return $file_info;
}
if($return_var === 0) // Set video size
$file_info['width'] = (int)$stream_info['video']['width'];
$file_info['height'] = (int)$stream_info['video']['height'];
$file_info['duration'] = (int)$stream_info['video']['duration'];
// MP4
if ($file_info['extension'] === 'mp4')
{
// Treat as GIF
if ($config->video_mp4_gif_time && $file_info['duration'] <= $config->video_mp4_gif_time && empty($stream_info['audio']))
{ {
$file_info['thumbnail'] = $output_name; $file_info['original_type'] = 'image/gif';
} }
} }
// Treat as GIF // Generate a thumbnail image
if ($config->video_mp4_gif_time && $file_info['extension'] === 'mp4') if ($config->video_thumbnail)
{ {
$command = $config->ffprobe_command; $thumbnail_name = $file_info['tmp_name'] . '.thumbnail.jpeg';
$command .= ' -i ' . escapeshellarg($file_info['tmp_name']); $command = $config->ffmpeg_command;
$command .= ' -show_entries format=duration -v quiet -of csv="p=0"'; $command .= sprintf(' -ss 00:00:00.%d -i %s -vframes 1', mt_rand(0, 99), escapeshellarg($file_info['tmp_name']));
$file_info['duration'] = (int)floor(@exec($command)); $command .= ' ' . escapeshellarg($thumbnail_name);
if($file_info['duration'] <= $config->video_mp4_gif_time) @exec($command, $output, $return_var);
if ($return_var === 0)
{ {
$file_info['original_type'] = 'image/gif'; $file_info['thumbnail'] = $thumbnail_name;
} }
} }

View file

@ -95,7 +95,7 @@ $lang->about_image_autoconv_gif2mp4 = 'convert animated GIF images into MP4 vide
$lang->video_thumbnail = 'Video Thumbnail'; $lang->video_thumbnail = 'Video Thumbnail';
$lang->about_video_thumbnail = 'extract a thumbnail image from uploaded video.'; $lang->about_video_thumbnail = 'extract a thumbnail image from uploaded video.';
$lang->video_mp4_gif_time = 'Treat as GIF'; $lang->video_mp4_gif_time = 'Treat as GIF';
$lang->about_video_mp4_gif_time = 'treat MP4 videos with duration less than the set time as GIF images, and play with auto and loop.'; $lang->about_video_mp4_gif_time = 'treat silent MP4 videos with duration less than the set time as GIF images, and play with auto and loop.';
$lang->ffmpeg_path = 'FFmpeg path'; $lang->ffmpeg_path = 'FFmpeg path';
$lang->ffprobe_path = 'FFprobe path'; $lang->ffprobe_path = 'FFprobe path';
$lang->msg_cannot_use_ffmpeg = 'FFmpeg and FFprobe must can be executed by PHP'; $lang->msg_cannot_use_ffmpeg = 'FFmpeg and FFprobe must can be executed by PHP';

View file

@ -96,7 +96,7 @@ $lang->about_image_autoconv_gif2mp4 = '움직이는 GIF 이미지를 MP4 동영
$lang->video_thumbnail = '동영상 섬네일'; $lang->video_thumbnail = '동영상 섬네일';
$lang->about_video_thumbnail = '업로드된 동영상에서 섬네일 이미지를 추출합니다.'; $lang->about_video_thumbnail = '업로드된 동영상에서 섬네일 이미지를 추출합니다.';
$lang->video_mp4_gif_time = 'GIF로 취급'; $lang->video_mp4_gif_time = 'GIF로 취급';
$lang->about_video_mp4_gif_time = '설정된 시간 이하의 길이를 가진 짧 MP4 동영상을 GIF 이미지로 취급하여 자동 및 반복 재생 상태로 삽입합니다.'; $lang->about_video_mp4_gif_time = '설정된 시간 이하의 길이를 가진 짧고 소리 없는 MP4 동영상을 GIF 이미지로 취급하여 자동 및 반복 재생 상태로 삽입합니다.';
$lang->ffmpeg_path = 'FFmpeg 경로'; $lang->ffmpeg_path = 'FFmpeg 경로';
$lang->ffprobe_path = 'FFprobe 경로'; $lang->ffprobe_path = 'FFprobe 경로';
$lang->msg_cannot_use_ffmpeg = 'PHP에서 FFmpeg 및 FFprobe를 실행할 수 있어야 합니다.'; $lang->msg_cannot_use_ffmpeg = 'PHP에서 FFmpeg 및 FFprobe를 실행할 수 있어야 합니다.';