李帅

1.继续调试ffmpeg命令

......@@ -46,6 +46,9 @@ class DevFFmpeg extends Command
*/
public function handle()
{
$mv = AdminMakeVideo::query()->first();
dd($mv->getContentPosition());
$content = '题破山寺后禅院' . "\t" . ' -- 常建' . PHP_EOL .
'清晨入古寺,初日照高林。' . PHP_EOL .
'曲径通幽处,禅房花木深。' . PHP_EOL .
......
......@@ -61,6 +61,7 @@ class MakeVideo implements ShouldQueue
$signature_x = 0;
$signature_y = -20;
$content = $adminMakeVideo->poem->content;
$content_position = $adminMakeVideo->getContentPosition();
// 转换logo大小
// $watermark = $this->translateLogo(Storage::disk('public')->path('image/logo.jpg'));
......@@ -77,7 +78,7 @@ class MakeVideo implements ShouldQueue
$animate = $this->makeAnimate($last_frame_video, $end_wallpaper, '', $signature_x, $signature_y, $font);
}
$video = $this->getTempPath();
$video_temp = $this->getTempPath();
$cmd = $this->ffmpeg . ' -y ' .
' -i ' . escapeshellarg($file) .
' -i ' . escapeshellarg($animate) .
......@@ -89,30 +90,31 @@ class MakeVideo implements ShouldQueue
'text=' . escapeshellarg($content) . ':' .
'fontsize=43:' .
'fontcolor=white@1.0:' .
'x=main_w/2' . '-260' . ':' .
'y=main_h/2' . '-20' . ':' .
'x=' . $content_position[0] . ':' .
'y=' . $content_position[1] . ':' .
'box=1:boxcolor=0xd0cdcc@0.5' .
'" [text];' .
'[text] [2:v]overlay=' . $watermark_x . ':' . $watermark_y . '[water];[water][0:1][1:0][1:1] concat=n=2:v=1:a=1[v][a]" ' .
' -map [v] -map [a]' .
' -c:v libx264 -bt 256k -r 25' .
' -ar 44100 -ac 2 -qmin 30 -qmax 60 -profile:v baseline -preset fast ' .
escapeshellarg($video);
escapeshellarg($video_temp);
$this->execmd($cmd);
if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){
$video_temp = $video;
$video = $this->getTempPath();
if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){
$thumbnail = Storage::disk('public')->path($adminMakeVideo->thumbnail_url);
}else{
$thumbnail = $last_frame_video;
}
$cmd = $this->ffmpeg. ' -y'.
' -i ' . escapeshellarg($video_temp).
' -i ' . escapeshellarg(Storage::disk('public')->path($adminMakeVideo->thumbnail_url)).
' -i ' . escapeshellarg($thumbnail).
' -map 1 -map 0 -c copy -disposition:0 attached_pic '.
escapeshellarg($video);
$this->execmd($cmd);
}
// 全部合成以后创建 临境
$video_info = $this->mediainfo($video);
......
......@@ -51,4 +51,11 @@ class AdminMakeVideo extends Model
{
return $this->hasOne(VideoTemp::class,'id','temp_id');
}
public function getContentPosition($field = 'one_poem')
{
$component = $this->temp()->first()->components()->where('name','=',$field)->first();
return VideoTemp::POSITION_FFMPEG[$component->position];
}
}
......
......@@ -16,6 +16,12 @@ class VideoTemp extends Model
'botLeft'=>'下左','botMiddle'=>'下中','botRight'=>'下右',
];
const POSITION_FFMPEG = [
'topLeft' => [0, 0], 'topMiddle' => ['(w-text_w)/2', 0], 'topRight' => ['w-text_w', 0],
'midLeft' => [0, '(h-text_h)/2'], 'midMiddle' => ['(w-text_w)/2', '(h-text_h)/2'], 'midRight' => ['w-text_w', '(h-text_h)/2'],
'botLeft' => [0, 'h-text_h'], 'botMiddle' => ['(w-text_w)/2', 'h-text_h'], 'botRight' => ['w-text_w', 'h-text_h'],
];
protected $table = 'video_temp';
protected $guarded = [''];
......