李帅

1.调试合成脚本程序

......@@ -212,6 +212,7 @@ class AdminMakeImmerse implements ShouldQueue
$opacity = $component->opacity ? $component->opacity / 100 : 0.5;
$font_file = $this->getAbsolutePath($component->font_file);
$text_bg_box = $component->text_bg_box ?? 0;
$font_size = $this->calcFontSize($component->font_size);
// 文字淡入淡出模式
if ($component->draw == 'fade'){
......@@ -219,13 +220,13 @@ class AdminMakeImmerse implements ShouldQueue
switch ($component->name){
case 'one_poem':
foreach ($this->adminMakeVideo->poem2->verses as $item) {
if ($item->content != '') $contents[] = $item->content;
if ($item->content != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width);
}
break;
case 'one_poem_with_annotate':
foreach ($this->adminMakeVideo->poem2->verses as $item) {
if ($item->content != '') $contents[] = $item->content;
if ($item->annotate != '') $contents[] = $item->annotate;
if ($item->content != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width);
if ($item->annotate != '') $contents[] = $this->autoEnter($item->content, $font_size, $this->output_width);
}
break;
case 'weather':
......@@ -251,13 +252,14 @@ class AdminMakeImmerse implements ShouldQueue
$sub_text .= 'drawtext="'.
'fontfile=' . escapeshellarg($font_file) . ':' .
'textfile=' . escapeshellarg($text_file) . ':' .
'fontsize=' . $this->calcFontSize($component->font_size) . ':' .
'fontsize=' . $font_size . ':' .
'fontcolor_expr=' . escapeshellarg($text_color . '%{eif\\\\: clip(255*(1*between(t\\, ' . $DS . ' + ' . $FID . '\\, ' . $DE . ' - ' . $FOD . ') + ((t - ' . $DS . ')/' . $FID . ')*between(t\\, ' . $DS . '\\, ' . $DS . ' + ' . $FID . ') + (-(t - ' . $DE . ')/' . $FOD . ')*between(t\\, ' . $DE . ' - ' . $FOD . '\\, ' . $DE . '))\\, 0\\, 255) \\\\: x\\\\: 2 }') . ':' .
'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' .
'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' .
'", ';
}
$drawtext .= $sub_text;
}
......@@ -269,7 +271,8 @@ class AdminMakeImmerse implements ShouldQueue
case 'one_poem':
$stanzas = '';
foreach ($this->adminMakeVideo->poem2->verses as $item) {
if ($item->content != '') $stanzas .= $item->content . "\n";
if ($item->content != '') $stanzas .= $this->autoEnter($item->content, $font_size, $this->output_width) . "\n";
}
$contents[] = $stanzas;
break;
......@@ -290,7 +293,7 @@ class AdminMakeImmerse implements ShouldQueue
$sub_text .= 'drawtext="'.
'fontfile=' . escapeshellarg($font_file) . ':' .
'textfile=' . escapeshellarg($text_file) . ':' .
'fontsize=' . $this->calcFontSize($component->font_size) . ':' .
'fontsize=' . $font_size . ':' .
'fontcolor=' . $text_color . '@' . $opacity . ':' .
'x=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][0]) . ':' .
'y=' . escapeshellarg(VideoTemp::POSITION_FFMPEG[$component->position][1]) . ':' .
......@@ -304,9 +307,28 @@ class AdminMakeImmerse implements ShouldQueue
return rtrim($drawtext,', ');
}
public function autoEnter($string, $font_width, $video_width)
{
$video_width = $video_width - 2 * $font_width; // 两侧留出空隙
$row_count = floor($video_width / $font_width);
echo $row_count;
$str_len = mb_strlen($string);
if ($str_len > $row_count) {
$tmp = array_chunk(
preg_split("//u", $string, -1, PREG_SPLIT_NO_EMPTY), $row_count);
$new_str = "";
foreach ($tmp as $t) {
$new_str .= join("", $t) . "\n";
}
return $new_str;
}else{
return $string;
}
}
public function calcFontSize($width)
{
return ceil($this->output_width / 360 * $width);
return floor($this->output_width / 360 * $width);
}
/**
......