Showing
4 changed files
with
32 additions
and
14 deletions
... | @@ -46,6 +46,9 @@ class DevFFmpeg extends Command | ... | @@ -46,6 +46,9 @@ class DevFFmpeg extends Command |
46 | */ | 46 | */ |
47 | public function handle() | 47 | public function handle() |
48 | { | 48 | { |
49 | + $mv = AdminMakeVideo::query()->first(); | ||
50 | + dd($mv->getContentPosition()); | ||
51 | + | ||
49 | $content = '题破山寺后禅院' . "\t" . ' -- 常建' . PHP_EOL . | 52 | $content = '题破山寺后禅院' . "\t" . ' -- 常建' . PHP_EOL . |
50 | '清晨入古寺,初日照高林。' . PHP_EOL . | 53 | '清晨入古寺,初日照高林。' . PHP_EOL . |
51 | '曲径通幽处,禅房花木深。' . PHP_EOL . | 54 | '曲径通幽处,禅房花木深。' . PHP_EOL . | ... | ... |
... | @@ -61,6 +61,7 @@ class MakeVideo implements ShouldQueue | ... | @@ -61,6 +61,7 @@ class MakeVideo implements ShouldQueue |
61 | $signature_x = 0; | 61 | $signature_x = 0; |
62 | $signature_y = -20; | 62 | $signature_y = -20; |
63 | $content = $adminMakeVideo->poem->content; | 63 | $content = $adminMakeVideo->poem->content; |
64 | + $content_position = $adminMakeVideo->getContentPosition(); | ||
64 | 65 | ||
65 | // 转换logo大小 | 66 | // 转换logo大小 |
66 | // $watermark = $this->translateLogo(Storage::disk('public')->path('image/logo.jpg')); | 67 | // $watermark = $this->translateLogo(Storage::disk('public')->path('image/logo.jpg')); |
... | @@ -77,7 +78,7 @@ class MakeVideo implements ShouldQueue | ... | @@ -77,7 +78,7 @@ class MakeVideo implements ShouldQueue |
77 | $animate = $this->makeAnimate($last_frame_video, $end_wallpaper, '', $signature_x, $signature_y, $font); | 78 | $animate = $this->makeAnimate($last_frame_video, $end_wallpaper, '', $signature_x, $signature_y, $font); |
78 | } | 79 | } |
79 | 80 | ||
80 | - $video = $this->getTempPath(); | 81 | + $video_temp = $this->getTempPath(); |
81 | $cmd = $this->ffmpeg . ' -y ' . | 82 | $cmd = $this->ffmpeg . ' -y ' . |
82 | ' -i ' . escapeshellarg($file) . | 83 | ' -i ' . escapeshellarg($file) . |
83 | ' -i ' . escapeshellarg($animate) . | 84 | ' -i ' . escapeshellarg($animate) . |
... | @@ -89,31 +90,32 @@ class MakeVideo implements ShouldQueue | ... | @@ -89,31 +90,32 @@ class MakeVideo implements ShouldQueue |
89 | 'text=' . escapeshellarg($content) . ':' . | 90 | 'text=' . escapeshellarg($content) . ':' . |
90 | 'fontsize=43:' . | 91 | 'fontsize=43:' . |
91 | 'fontcolor=white@1.0:' . | 92 | 'fontcolor=white@1.0:' . |
92 | - 'x=main_w/2' . '-260' . ':' . | 93 | + 'x=' . $content_position[0] . ':' . |
93 | - 'y=main_h/2' . '-20' . ':' . | 94 | + 'y=' . $content_position[1] . ':' . |
94 | 'box=1:boxcolor=0xd0cdcc@0.5' . | 95 | 'box=1:boxcolor=0xd0cdcc@0.5' . |
95 | '" [text];' . | 96 | '" [text];' . |
96 | '[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]" ' . | 97 | '[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]" ' . |
97 | ' -map [v] -map [a]' . | 98 | ' -map [v] -map [a]' . |
98 | ' -c:v libx264 -bt 256k -r 25' . | 99 | ' -c:v libx264 -bt 256k -r 25' . |
99 | ' -ar 44100 -ac 2 -qmin 30 -qmax 60 -profile:v baseline -preset fast ' . | 100 | ' -ar 44100 -ac 2 -qmin 30 -qmax 60 -profile:v baseline -preset fast ' . |
100 | - escapeshellarg($video); | 101 | + escapeshellarg($video_temp); |
101 | 102 | ||
102 | $this->execmd($cmd); | 103 | $this->execmd($cmd); |
103 | 104 | ||
105 | + $video = $this->getTempPath(); | ||
104 | if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){ | 106 | if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){ |
105 | - $video_temp = $video; | 107 | + $thumbnail = Storage::disk('public')->path($adminMakeVideo->thumbnail_url); |
106 | - $video = $this->getTempPath(); | 108 | + }else{ |
107 | - | 109 | + $thumbnail = $last_frame_video; |
108 | - $cmd = $this->ffmpeg. ' -y'. | ||
109 | - ' -i ' . escapeshellarg($video_temp). | ||
110 | - ' -i ' . escapeshellarg(Storage::disk('public')->path($adminMakeVideo->thumbnail_url)). | ||
111 | - ' -map 1 -map 0 -c copy -disposition:0 attached_pic '. | ||
112 | - escapeshellarg($video); | ||
113 | - | ||
114 | - $this->execmd($cmd); | ||
115 | } | 110 | } |
116 | 111 | ||
112 | + $cmd = $this->ffmpeg. ' -y'. | ||
113 | + ' -i ' . escapeshellarg($video_temp). | ||
114 | + ' -i ' . escapeshellarg($thumbnail). | ||
115 | + ' -map 1 -map 0 -c copy -disposition:0 attached_pic '. | ||
116 | + escapeshellarg($video); | ||
117 | + $this->execmd($cmd); | ||
118 | + | ||
117 | // 全部合成以后创建 临境 | 119 | // 全部合成以后创建 临境 |
118 | $video_info = $this->mediainfo($video); | 120 | $video_info = $this->mediainfo($video); |
119 | 121 | ... | ... |
... | @@ -51,4 +51,11 @@ class AdminMakeVideo extends Model | ... | @@ -51,4 +51,11 @@ class AdminMakeVideo extends Model |
51 | { | 51 | { |
52 | return $this->hasOne(VideoTemp::class,'id','temp_id'); | 52 | return $this->hasOne(VideoTemp::class,'id','temp_id'); |
53 | } | 53 | } |
54 | + | ||
55 | + public function getContentPosition($field = 'one_poem') | ||
56 | + { | ||
57 | + $component = $this->temp()->first()->components()->where('name','=',$field)->first(); | ||
58 | + | ||
59 | + return VideoTemp::POSITION_FFMPEG[$component->position]; | ||
60 | + } | ||
54 | } | 61 | } | ... | ... |
... | @@ -16,6 +16,12 @@ class VideoTemp extends Model | ... | @@ -16,6 +16,12 @@ class VideoTemp extends Model |
16 | 'botLeft'=>'下左','botMiddle'=>'下中','botRight'=>'下右', | 16 | 'botLeft'=>'下左','botMiddle'=>'下中','botRight'=>'下右', |
17 | ]; | 17 | ]; |
18 | 18 | ||
19 | + const POSITION_FFMPEG = [ | ||
20 | + 'topLeft' => [0, 0], 'topMiddle' => ['(w-text_w)/2', 0], 'topRight' => ['w-text_w', 0], | ||
21 | + 'midLeft' => [0, '(h-text_h)/2'], 'midMiddle' => ['(w-text_w)/2', '(h-text_h)/2'], 'midRight' => ['w-text_w', '(h-text_h)/2'], | ||
22 | + 'botLeft' => [0, 'h-text_h'], 'botMiddle' => ['(w-text_w)/2', 'h-text_h'], 'botRight' => ['w-text_w', 'h-text_h'], | ||
23 | + ]; | ||
24 | + | ||
19 | protected $table = 'video_temp'; | 25 | protected $table = 'video_temp'; |
20 | 26 | ||
21 | protected $guarded = ['']; | 27 | protected $guarded = ['']; | ... | ... |
-
Please register or login to post a comment