李帅

1.后台可上传图文内容。

...@@ -33,7 +33,7 @@ class AdminMakeVideoController extends AdminController ...@@ -33,7 +33,7 @@ class AdminMakeVideoController extends AdminController
33 $grid->column('title','标题'); 33 $grid->column('title','标题');
34 $grid->column('content','有感'); 34 $grid->column('content','有感');
35 $grid->column('url')->display(function ($url){ 35 $grid->column('url')->display(function ($url){
36 - return "<a target='_blank' href='". Storage::disk('public')->url(Str::after($url,'/public')) ."'>查看</a>"; 36 + return "<a target='_blank' href='". $url ."'>查看</a>";
37 }); 37 });
38 $grid->column('type','类型')->using([1 => '音频', 2 => '视频']); 38 $grid->column('type','类型')->using([1 => '音频', 2 => '视频']);
39 $grid->column('duration'); 39 $grid->column('duration');
...@@ -41,7 +41,12 @@ class AdminMakeVideoController extends AdminController ...@@ -41,7 +41,12 @@ class AdminMakeVideoController extends AdminController
41 $grid->column('poem_id'); 41 $grid->column('poem_id');
42 $grid->column('temp_id'); 42 $grid->column('temp_id');
43 $grid->column('thumbnail')->image(); 43 $grid->column('thumbnail')->image();
44 - $grid->column('bgm'); 44 + $grid->column('bgm')->display(function ($url){
45 + if (Str::of($url)->contains('.mp3'))
46 + return "<a target='_blank' href='". $url ."'>查看</a>";
47 + else
48 + return "<a target='_blank' href='". $url ."'>下载</a>";
49 + });
45 $grid->column('created_at'); 50 $grid->column('created_at');
46 $grid->column('updated_at')->sortable(); 51 $grid->column('updated_at')->sortable();
47 52
...@@ -168,4 +173,17 @@ class AdminMakeVideoController extends AdminController ...@@ -168,4 +173,17 @@ class AdminMakeVideoController extends AdminController
168 173
169 return $this->form()->response()->refresh()->success(trans('admin.save_succeeded')); 174 return $this->form()->response()->refresh()->success(trans('admin.save_succeeded'));
170 } 175 }
176 +
177 + public function destroy($id)
178 + {
179 + $immerse = Immerse::query()->find($id);
180 +
181 + Storage::disk('public')->delete($immerse->url);
182 + Storage::disk('public')->delete($immerse->thumbnail);
183 + Storage::disk('public')->delete($immerse->bgm);
184 +
185 +
186 + dd($id);
187 +// return $this->form()->destroy($id);
188 + }
171 } 189 }
......
...@@ -893,6 +893,18 @@ class DevFFmpeg extends Command ...@@ -893,6 +893,18 @@ class DevFFmpeg extends Command
893 893
894 return rtrim($drawtext,', '); 894 return rtrim($drawtext,', ');
895 } 895 }
896 +
897 + public function calcFontSize($width, $content)
898 + {
899 + $max_len = 1;
900 + foreach (explode("\n",$content) as $item){
901 + if (mb_strlen($item) > $max_len){
902 + $max_len = mb_strlen($item);
903 + }
904 + }
905 +
906 + return ceil(800 * $width / 100 / $max_len);
907 + }
896 } 908 }
897 909
898 910
......
...@@ -8,6 +8,7 @@ use App\Models\UserMakeVideo; ...@@ -8,6 +8,7 @@ use App\Models\UserMakeVideo;
8 use App\Jobs\UserMakeVideo as MakeVideo; 8 use App\Jobs\UserMakeVideo as MakeVideo;
9 use App\Jobs\UserMakeImages as MakeImages; 9 use App\Jobs\UserMakeImages as MakeImages;
10 use Illuminate\Http\Request; 10 use Illuminate\Http\Request;
11 +use Illuminate\Support\Facades\Auth;
11 use Illuminate\Support\Facades\Storage; 12 use Illuminate\Support\Facades\Storage;
12 use Illuminate\Support\Facades\Validator; 13 use Illuminate\Support\Facades\Validator;
13 use Illuminate\Support\Str; 14 use Illuminate\Support\Str;
...@@ -49,67 +50,56 @@ class ImmerseController extends Controller ...@@ -49,67 +50,56 @@ class ImmerseController extends Controller
49 50
50 $validated = $validator->validated(); 51 $validated = $validator->validated();
51 52
52 - if (Str::contains($validated['item_url'],'//')){
53 - $item_url = '' ;
54 - }elseif (Str::contains($validated['item_url'],'/storage/app/public/')){
55 - $item_url = $validated['item_url'];
56 - }else{
57 - $item_url = Storage::disk('public')->path($validated['item_url']);
58 - }
59 -
60 $immerse = Immerse::query()->find($request->item_id); 53 $immerse = Immerse::query()->find($request->item_id);
61 -
62 if ($validated['type'] == 1){ 54 if ($validated['type'] == 1){
63 - // 图文音频 55 + $create = Immerse::query()->create([
64 - $create = UserMakeVideo::query()->create([ 56 + 'user_id' => Auth::user()->getAuthIdentifier(),
57 + 'title' => '',
58 + 'content' => $validated['content'],
59 + 'url' => '',
60 + 'type' => $validated['type'],
61 + 'duration' => 0,
62 + 'size' => 0,
65 'poem_id' => $immerse->poem_id, 63 'poem_id' => $immerse->poem_id,
66 - 'type' => $immerse->type,
67 - 'video_url' => $item_url,
68 - 'image_url' => $immerse->image_url,
69 - 'bg_music' => $immerse->bg_music,
70 - 'bgm_url' => $immerse->bgm_url,
71 - 'feel' => $validated['content'],
72 - 'weather' => $validated['weather'],
73 'temp_id' => $immerse->temp_id, 64 'temp_id' => $immerse->temp_id,
74 - 'thumbnail' => $validated['thumbnail_url'] ? 1 : 0, 65 + 'thumbnail' => $immerse->thumbnail,
75 - 'thumbnail_url' => $validated['thumbnail_url'], 66 + 'bgm' => $validated['item_url'],
76 ]); 67 ]);
68 +
77 // 添加至队列 69 // 添加至队列
78 MakeImages::dispatch($create); 70 MakeImages::dispatch($create);
79 }else{ 71 }else{
80 // 视频 72 // 视频
81 - $create = UserMakeVideo::query()->create([ 73 + $create = Immerse::query()->create([
74 + 'user_id' => Auth::user()->getAuthIdentifier(),
75 + 'title' => '',
76 + 'content' => $validated['content'],
77 + 'url' => '',
78 + 'type' => $validated['type'],
79 + 'duration' => 0,
80 + 'size' => 0,
82 'poem_id' => $immerse->poem_id, 81 'poem_id' => $immerse->poem_id,
83 - 'type' => $immerse->type,
84 - 'video_url' => $item_url,
85 - 'image_url' => $immerse->image_url,
86 - 'bg_music' => $immerse->bg_music,
87 - 'bgm_url' => $immerse->bgm_url,
88 - 'feel' => $validated['content'],
89 - 'weather' => $validated['weather'],
90 'temp_id' => $immerse->temp_id, 82 'temp_id' => $immerse->temp_id,
91 - 'thumbnail' => $validated['thumbnail_url'] ? 1 : 0, 83 + 'thumbnail' => '',
92 - 'thumbnail_url' => $validated['thumbnail_url'], 84 + 'bgm' => $immerse->bgm,
93 ]); 85 ]);
94 86
95 // 添加至队列 87 // 添加至队列
96 - MakeVideo::dispatch($create); 88 + MakeVideo::dispatch($create, $validated['item_url']);
97 } 89 }
98 90
99 - 91 + return Response::created($create->id);
100 -
101 - return Response::created();
102 } 92 }
103 93
104 /** 94 /**
105 * Display the specified resource. 95 * Display the specified resource.
106 * 96 *
107 * @param int $id 97 * @param int $id
108 - * @return \Illuminate\Http\Response 98 + * @return \Illuminate\Http\JsonResponse
109 */ 99 */
110 public function show($id) 100 public function show($id)
111 { 101 {
112 - // 102 + return Response::success(Immerse::query()->find($id));
113 } 103 }
114 104
115 /** 105 /**
......
...@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V1; ...@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V1;
4 4
5 use App\Http\Controllers\Controller; 5 use App\Http\Controllers\Controller;
6 use App\Jobs\SendVerificationMessage; 6 use App\Jobs\SendVerificationMessage;
7 +use App\Models\Immerse;
7 use App\Models\User; 8 use App\Models\User;
8 use App\Models\UserProfile; 9 use App\Models\UserProfile;
9 use Illuminate\Http\Request; 10 use Illuminate\Http\Request;
...@@ -136,4 +137,27 @@ class UserController extends Controller ...@@ -136,4 +137,27 @@ class UserController extends Controller
136 137
137 return Response::success($user); 138 return Response::success($user);
138 } 139 }
140 +
141 + public function videos(Request $request)
142 + {
143 + $type = $request->get('type');
144 +
145 + $user_id = Auth::user()->getAuthIdentifier();
146 +
147 + $immerse = Immerse::query()->where('user_id', 1);
148 + switch ($type)
149 + {
150 + case 0 : // 审核中...
151 + $data = $immerse->where('is_check', 0)->get();
152 + break;
153 + case 1 : // 审核通过...
154 + $data = $immerse->where('is_check',1)->get();
155 + break;
156 + default: // 全部
157 + $data = $immerse->get();
158 + break;
159 + }
160 +
161 + return Response::success($data);
162 + }
139 } 163 }
......
...@@ -80,14 +80,14 @@ class MakeImages implements ShouldQueue ...@@ -80,14 +80,14 @@ class MakeImages implements ShouldQueue
80 'user_id' => 1, 80 'user_id' => 1,
81 'title' => '', 81 'title' => '',
82 'content' => $this->adminMakeVideo->feel, 82 'content' => $this->adminMakeVideo->feel,
83 - 'url' => $output, 83 + 'url' => str_replace(Storage::disk('public')->path(''),'',$output),
84 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1, 84 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
85 'duration' => 0, 85 'duration' => 0,
86 'size' => $video_info['format']['size'], 86 'size' => $video_info['format']['size'],
87 'poem_id' => $this->adminMakeVideo->poem_id, 87 'poem_id' => $this->adminMakeVideo->poem_id,
88 'temp_id' => $this->adminMakeVideo->temp_id, 88 'temp_id' => $this->adminMakeVideo->temp_id,
89 - 'thumbnail' => '', 89 + 'thumbnail' => str_replace(Storage::disk('public')->path(''),'',$image),
90 - 'bgm' => $this->adminMakeVideo->bgm_url, 90 + 'bgm' => str_replace(Storage::disk('public')->path(''),'',$this->adminMakeVideo->bgm_url),
91 ]; 91 ];
92 92
93 }else{ 93 }else{
...@@ -145,8 +145,6 @@ class MakeImages implements ShouldQueue ...@@ -145,8 +145,6 @@ class MakeImages implements ShouldQueue
145 145
146 if (!$this->execmd($cmd)) return; 146 if (!$this->execmd($cmd)) return;
147 147
148 -
149 -
150 // 全部合成以后创建 临境 148 // 全部合成以后创建 临境
151 $video_info = $this->mediainfo($output); 149 $video_info = $this->mediainfo($output);
152 150
...@@ -154,14 +152,14 @@ class MakeImages implements ShouldQueue ...@@ -154,14 +152,14 @@ class MakeImages implements ShouldQueue
154 'user_id' => 1, 152 'user_id' => 1,
155 'title' => '', 153 'title' => '',
156 'content' => $this->adminMakeVideo->feel, 154 'content' => $this->adminMakeVideo->feel,
157 - 'url' => $output, 155 + 'url' => str_replace(Storage::disk('public')->path(''),'',$output),
158 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1, 156 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
159 'duration' => $video_info['format']['duration'], 157 'duration' => $video_info['format']['duration'],
160 'size' => $video_info['format']['size'], 158 'size' => $video_info['format']['size'],
161 'poem_id' => $this->adminMakeVideo->poem_id, 159 'poem_id' => $this->adminMakeVideo->poem_id,
162 'temp_id' => $this->adminMakeVideo->temp_id, 160 'temp_id' => $this->adminMakeVideo->temp_id,
163 - 'thumbnail' => '', 161 + 'thumbnail' => str_replace(Storage::disk('public')->path(''),'',$this->adminMakeVideo->images_url),
164 - 'bgm' => $this->adminMakeVideo->bgm_url, 162 + 'bgm' => str_replace(Storage::disk('public')->path(''),'',$this->adminMakeVideo->bgm_url),
165 ]; 163 ];
166 } 164 }
167 165
......
...@@ -161,19 +161,7 @@ class MakeVideo implements ShouldQueue ...@@ -161,19 +161,7 @@ class MakeVideo implements ShouldQueue
161 161
162 if (!$this->execmd($cmd)) return; 162 if (!$this->execmd($cmd)) return;
163 163
164 -// $video = $this->getTempPath(); 164 + try{
165 -// if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){
166 -// $thumbnail = Storage::disk('public')->path($adminMakeVideo->thumbnail_url);
167 -// }else{
168 -// $thumbnail = $last_frame_video;
169 -// }
170 -// $cmd = $this->ffmpeg. ' -y'.
171 -// ' -i ' . escapeshellarg($video_temp).
172 -// ' -i ' . escapeshellarg($thumbnail).
173 -// ' -map 1 -map 0 -c copy -disposition:0 attached_pic '.
174 -// escapeshellarg($video);
175 -// $this->execmd($cmd);
176 -
177 // 全部合成以后创建 临境 165 // 全部合成以后创建 临境
178 $video_info = $this->mediainfo($video); 166 $video_info = $this->mediainfo($video);
179 167
...@@ -181,16 +169,21 @@ class MakeVideo implements ShouldQueue ...@@ -181,16 +169,21 @@ class MakeVideo implements ShouldQueue
181 'user_id' => 1, 169 'user_id' => 1,
182 'title' => '', 170 'title' => '',
183 'content' => $this->adminMakeVideo->feel, 171 'content' => $this->adminMakeVideo->feel,
184 - 'url' => $video, 172 + 'url' => str_replace(Storage::disk('public')->path(''),'',$video),
185 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1, 173 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
186 'duration' => $video_info['format']['duration'], 174 'duration' => $video_info['format']['duration'],
187 'size' => $video_info['format']['size'], 175 'size' => $video_info['format']['size'],
188 'poem_id' => $this->adminMakeVideo->poem_id, 176 'poem_id' => $this->adminMakeVideo->poem_id,
189 'temp_id' => $this->adminMakeVideo->temp_id, 177 'temp_id' => $this->adminMakeVideo->temp_id,
190 - 'thumbnail' => $thumbnail, 178 + 'thumbnail' => '',
191 - 'bgm' => $this->adminMakeVideo->bgm_url, 179 + 'state' => 1,
180 + 'bgm' => $this->adminMakeVideo->bgm_url ?? '',
192 ]); 181 ]);
193 182
183 + }catch (\Exception $exception){
184 + echo $exception->getMessage();
185 + }
186 +
194 } 187 }
195 188
196 /** 189 /**
...@@ -605,7 +598,7 @@ class MakeVideo implements ShouldQueue ...@@ -605,7 +598,7 @@ class MakeVideo implements ShouldQueue
605 switch ($component->name){ 598 switch ($component->name){
606 case 'one_poem': 599 case 'one_poem':
607 $content = $this->adminMakeVideo->poem->content; 600 $content = $this->adminMakeVideo->poem->content;
608 - $text_file = $this->getTempPath('txt'); 601 + $text_file = $this->getTempPath('.txt');
609 file_put_contents($text_file, $content); 602 file_put_contents($text_file, $content);
610 603
611 $text_color = $component->text_color ?? 'white'; 604 $text_color = $component->text_color ?? 'white';
...@@ -690,6 +683,6 @@ class MakeVideo implements ShouldQueue ...@@ -690,6 +683,6 @@ class MakeVideo implements ShouldQueue
690 } 683 }
691 } 684 }
692 685
693 - return ceil($this->width * $width / 10 / $max_len); 686 + return ceil($this->width * $width / 100 / $max_len);
694 } 687 }
695 } 688 }
......
...@@ -12,13 +12,17 @@ use Illuminate\Contracts\Queue\ShouldQueue; ...@@ -12,13 +12,17 @@ use Illuminate\Contracts\Queue\ShouldQueue;
12 use Illuminate\Foundation\Bus\Dispatchable; 12 use Illuminate\Foundation\Bus\Dispatchable;
13 use Illuminate\Queue\InteractsWithQueue; 13 use Illuminate\Queue\InteractsWithQueue;
14 use Illuminate\Queue\SerializesModels; 14 use Illuminate\Queue\SerializesModels;
15 +use Illuminate\Support\Facades\File;
16 +use Illuminate\Support\Facades\Log;
15 use Illuminate\Support\Facades\Storage; 17 use Illuminate\Support\Facades\Storage;
16 18
17 class UserMakeImages implements ShouldQueue 19 class UserMakeImages implements ShouldQueue
18 { 20 {
19 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; 21 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
20 22
21 - public $adminMakeVideo; 23 + public $debug = true;
24 +
25 + public $immerse;
22 26
23 protected $ffmpeg; 27 protected $ffmpeg;
24 28
...@@ -32,12 +36,12 @@ class UserMakeImages implements ShouldQueue ...@@ -32,12 +36,12 @@ class UserMakeImages implements ShouldQueue
32 36
33 /** 37 /**
34 * Create a new job instance. 38 * Create a new job instance.
35 - * @param AdminMakeVideo $adminMakeVideo 39 + * @param Immerse $immerse
36 * @return void 40 * @return void
37 */ 41 */
38 - public function __construct(AdminMakeVideo $adminMakeVideo) 42 + public function __construct(Immerse $immerse)
39 { 43 {
40 - $this->adminMakeVideo = $adminMakeVideo; 44 + $this->immerse = $immerse;
41 45
42 $this->ffmpeg = env('FFMPEG_CMD'); 46 $this->ffmpeg = env('FFMPEG_CMD');
43 $this->ffprobe = env('FFPROBE_CMD'); 47 $this->ffprobe = env('FFPROBE_CMD');
...@@ -52,16 +56,16 @@ class UserMakeImages implements ShouldQueue ...@@ -52,16 +56,16 @@ class UserMakeImages implements ShouldQueue
52 public function handle() 56 public function handle()
53 { 57 {
54 $watermark = Storage::disk('public')->path('ffmpeg/LOGO_eng.png'); 58 $watermark = Storage::disk('public')->path('ffmpeg/LOGO_eng.png');
55 - $image = Storage::disk('public')->path($this->adminMakeVideo->images_url); 59 + $image = Storage::disk('public')->path($this->immerse->thumbnail);
60 + if (!File::exists($image)) return;
61 + if ($this->debug) Log::debug('image url :' . $image);
56 $media_info = $this->mediainfo($image); 62 $media_info = $this->mediainfo($image);
57 $this->width = $width = $media_info['streams'][0]['width']; 63 $this->width = $width = $media_info['streams'][0]['width'];
58 $this->height = $height = $media_info['streams'][0]['height']; 64 $this->height = $height = $media_info['streams'][0]['height'];
59 65
60 - if ($this->adminMakeVideo->type == 2 && $this->adminMakeVideo->bg_music == 0){ 66 + if ($this->immerse->type == 2 && $this->immerse->bgm){
61 // 没有背景音,单图一张,输出为单图。 67 // 没有背景音,单图一张,输出为单图。
62 -
63 $output = $this->getTempPath('.png',false); 68 $output = $this->getTempPath('.png',false);
64 -
65 $cmd = $this->ffmpeg . ' -y '. 69 $cmd = $this->ffmpeg . ' -y '.
66 ' -i ' . escapeshellarg($image). 70 ' -i ' . escapeshellarg($image).
67 ' -i ' . escapeshellarg($watermark). 71 ' -i ' . escapeshellarg($watermark).
...@@ -75,22 +79,9 @@ class UserMakeImages implements ShouldQueue ...@@ -75,22 +79,9 @@ class UserMakeImages implements ShouldQueue
75 79
76 // 全部合成以后创建 临境 80 // 全部合成以后创建 临境
77 $video_info = $this->mediainfo($output); 81 $video_info = $this->mediainfo($output);
78 -
79 - $create = [
80 - 'user_id' => 1,
81 - 'title' => '',
82 - 'content' => $this->adminMakeVideo->feel,
83 - 'url' => $output,
84 - 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
85 - 'duration' => 0,
86 - 'size' => $video_info['format']['size'],
87 - 'poem_id' => $this->adminMakeVideo->poem_id,
88 - 'temp_id' => $this->adminMakeVideo->temp_id,
89 - 'thumbnail' => '',
90 - 'bgm' => $this->adminMakeVideo->bgm_url,
91 - ];
92 -
93 }else{ 82 }else{
83 + // 有背景音 单图合成视频,时长为音频时长,音频加入背景音
84 + $bgm = Storage::disk('public')->path($this->immerse->bgm);
94 85
95 $end_wallpaper = Storage::disk('public')->path('ffmpeg/end_wallpaper.png'); 86 $end_wallpaper = Storage::disk('public')->path('ffmpeg/end_wallpaper.png');
96 $thumbnail = Storage::disk('public')->path('ffmpeg/thumbnail.png'); 87 $thumbnail = Storage::disk('public')->path('ffmpeg/thumbnail.png');
...@@ -100,10 +91,6 @@ class UserMakeImages implements ShouldQueue ...@@ -100,10 +91,6 @@ class UserMakeImages implements ShouldQueue
100 // 生成贴纸和签名 91 // 生成贴纸和签名
101 $end_wallpaper = $this->wallpaperWithSignature($end_wallpaper, $thumbnail, $signature, $font); 92 $end_wallpaper = $this->wallpaperWithSignature($end_wallpaper, $thumbnail, $signature, $font);
102 93
103 - // 有背景音 单图合成视频,时长为音频时长,音频加入背景音
104 - $bgm = Storage::disk('public')->path($this->adminMakeVideo->bgm_url);
105 -
106 -
107 // 制作最后一帧 94 // 制作最后一帧
108 $size = $this->width . 'x' . $this->height; 95 $size = $this->width . 'x' . $this->height;
109 $time_length = 0.7; 96 $time_length = 0.7;
...@@ -127,7 +114,6 @@ class UserMakeImages implements ShouldQueue ...@@ -127,7 +114,6 @@ class UserMakeImages implements ShouldQueue
127 $signature_y = -20; 114 $signature_y = -20;
128 $animate = $this->makeAnimate($last_frame_video, $end_wallpaper, '', $signature_x, $signature_y, $font); 115 $animate = $this->makeAnimate($last_frame_video, $end_wallpaper, '', $signature_x, $signature_y, $font);
129 116
130 -
131 $output = $this->getTempPath('.mp4',false); 117 $output = $this->getTempPath('.mp4',false);
132 118
133 $cmd = $this->ffmpeg . ' -y ' . 119 $cmd = $this->ffmpeg . ' -y ' .
...@@ -145,27 +131,15 @@ class UserMakeImages implements ShouldQueue ...@@ -145,27 +131,15 @@ class UserMakeImages implements ShouldQueue
145 131
146 if (!$this->execmd($cmd)) return; 132 if (!$this->execmd($cmd)) return;
147 133
148 -
149 -
150 - // 全部合成以后创建 临境
151 $video_info = $this->mediainfo($output); 134 $video_info = $this->mediainfo($output);
152 -
153 - $create = [
154 - 'user_id' => 1,
155 - 'title' => '',
156 - 'content' => $this->adminMakeVideo->feel,
157 - 'url' => $output,
158 - 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
159 - 'duration' => $video_info['format']['duration'],
160 - 'size' => $video_info['format']['size'],
161 - 'poem_id' => $this->adminMakeVideo->poem_id,
162 - 'temp_id' => $this->adminMakeVideo->temp_id,
163 - 'thumbnail' => '',
164 - 'bgm' => $this->adminMakeVideo->bgm_url,
165 - ];
166 } 135 }
167 136
168 - Immerse::query()->create($create); 137 + $this->immerse->query()->update([
138 + 'url' => str_replace(Storage::disk('public')->path(''),'',$output),
139 + 'state' => 1,
140 + 'duration' => $video_info['format']['duration'] ?? 0,
141 + 'size' => $video_info['format']['size'],
142 + ]);
169 } 143 }
170 144
171 /*** 145 /***
......
...@@ -20,7 +20,9 @@ class UserMakeVideo implements ShouldQueue ...@@ -20,7 +20,9 @@ class UserMakeVideo implements ShouldQueue
20 { 20 {
21 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; 21 use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
22 22
23 - public $adminMakeVideo; 23 + public $immerse;
24 +
25 + public $resource_url;
24 26
25 protected $ffmpeg; 27 protected $ffmpeg;
26 28
...@@ -32,12 +34,14 @@ class UserMakeVideo implements ShouldQueue ...@@ -32,12 +34,14 @@ class UserMakeVideo implements ShouldQueue
32 34
33 /** 35 /**
34 * Create a new job instance. 36 * Create a new job instance.
35 - * @param AdminMakeVideo $adminMakeVideo 37 + * @param Immerse $immerse
36 * @return void 38 * @return void
37 */ 39 */
38 - public function __construct(\App\Models\UserMakeVideo $adminMakeVideo) 40 + public function __construct(Immerse $immerse, $resource_url)
39 { 41 {
40 - $this->adminMakeVideo = $adminMakeVideo; 42 + $this->immerse = $immerse;
43 +
44 + $this->resource_url = $resource_url;
41 45
42 $this->ffmpeg = env('FFMPEG_CMD'); 46 $this->ffmpeg = env('FFMPEG_CMD');
43 $this->ffprobe = env('FFPROBE_CMD'); 47 $this->ffprobe = env('FFPROBE_CMD');
...@@ -51,10 +55,9 @@ class UserMakeVideo implements ShouldQueue ...@@ -51,10 +55,9 @@ class UserMakeVideo implements ShouldQueue
51 */ 55 */
52 public function handle() 56 public function handle()
53 { 57 {
54 - $adminMakeVideo = $this->adminMakeVideo; 58 + $file = Storage::disk('public')->path($this->resource_url);
55 - $file = Storage::disk('public')->path($adminMakeVideo->video_url); 59 + $is_bgm = isset($this->immerse->bgm);
56 - $is_bgm = $adminMakeVideo->bg_music; 60 + $bgm = Storage::disk('public')->path($this->immerse->bgm);
57 - $bgm = Storage::disk('public')->path($adminMakeVideo->bgm_url);
58 61
59 // 1.getmediainfo 记录时长,音频视频取最长。 62 // 1.getmediainfo 记录时长,音频视频取最长。
60 $cmd = $this->ffprobe . ' -v quiet -print_format json -show_format -show_streams ' . escapeshellarg($file); 63 $cmd = $this->ffprobe . ' -v quiet -print_format json -show_format -show_streams ' . escapeshellarg($file);
...@@ -66,7 +69,7 @@ class UserMakeVideo implements ShouldQueue ...@@ -66,7 +69,7 @@ class UserMakeVideo implements ShouldQueue
66 } 69 }
67 70
68 /** 记录媒体信息时长*/ 71 /** 记录媒体信息时长*/
69 - $media_file_time_length = isset($media_info['format']['duration']) ? $media_info['format']['duration'] : 0; 72 + $media_file_time_length = isset($media_info['format']['duration']) ?: 0;
70 if ($media_info['streams'][0]['codec_type'] !== 'video') { 73 if ($media_info['streams'][0]['codec_type'] !== 'video') {
71 Log::channel('daily')->error('视频没有video track'); 74 Log::channel('daily')->error('视频没有video track');
72 return; 75 return;
...@@ -120,7 +123,7 @@ class UserMakeVideo implements ShouldQueue ...@@ -120,7 +123,7 @@ class UserMakeVideo implements ShouldQueue
120 $thumbnail = Storage::disk('public')->path('ffmpeg') . "/thumbnail.png"; 123 $thumbnail = Storage::disk('public')->path('ffmpeg') . "/thumbnail.png";
121 $font = Storage::disk('public')->path('ffmpeg') . "/arialuni.ttf"; 124 $font = Storage::disk('public')->path('ffmpeg') . "/arialuni.ttf";
122 125
123 - $user = User::query()->find($this->adminMakeVideo->user_id); 126 + $user = User::query()->find($this->immerse->user_id);
124 $signature = $user->nickname; 127 $signature = $user->nickname;
125 128
126 // 生成贴纸和签名 129 // 生成贴纸和签名
...@@ -164,36 +167,17 @@ class UserMakeVideo implements ShouldQueue ...@@ -164,36 +167,17 @@ class UserMakeVideo implements ShouldQueue
164 167
165 if (!$this->execmd($cmd)) return; 168 if (!$this->execmd($cmd)) return;
166 169
167 -// $video = $this->getTempPath();
168 -// if ( $adminMakeVideo->thumbnail == 1 && $adminMakeVideo->thumbnail_url){
169 -// $thumbnail = Storage::disk('public')->path($adminMakeVideo->thumbnail_url);
170 -// }else{
171 -// $thumbnail = $last_frame_video;
172 -// }
173 -// $cmd = $this->ffmpeg. ' -y'.
174 -// ' -i ' . escapeshellarg($video_temp).
175 -// ' -i ' . escapeshellarg($thumbnail).
176 -// ' -map 1 -map 0 -c copy -disposition:0 attached_pic '.
177 -// escapeshellarg($video);
178 -// $this->execmd($cmd);
179 -
180 // 全部合成以后创建 临境 170 // 全部合成以后创建 临境
181 $video_info = $this->mediainfo($video); 171 $video_info = $this->mediainfo($video);
182 172
183 - Immerse::query()->create([ 173 + $this->immerse->query()->update([
184 - 'user_id' => $this->adminMakeVideo->user_id, 174 + 'url' => str_replace(Storage::disk('public')->path(''),'',$output),
185 - 'title' => '', 175 + 'state' => 1,
186 - 'content' => $this->adminMakeVideo->feel, 176 + 'duration' => $video_info['format']['duration'] ?? 0,
187 - 'url' => $video,
188 - 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1,
189 - 'duration' => $video_info['format']['duration'],
190 'size' => $video_info['format']['size'], 177 'size' => $video_info['format']['size'],
191 - 'poem_id' => $this->adminMakeVideo->poem_id,
192 - 'temp_id' => $this->adminMakeVideo->temp_id,
193 - 'thumbnail' => $thumbnail,
194 - 'bgm' => $this->adminMakeVideo->bgm_url,
195 ]); 178 ]);
196 179
180 + return;
197 } 181 }
198 182
199 /** 183 /**
...@@ -598,7 +582,7 @@ class UserMakeVideo implements ShouldQueue ...@@ -598,7 +582,7 @@ class UserMakeVideo implements ShouldQueue
598 582
599 public function getTextContentString() 583 public function getTextContentString()
600 { 584 {
601 - $components = $this->adminMakeVideo->temp()->first()->components()->get(); 585 + $components = $this->immerse->temp()->first()->components()->get();
602 586
603 $font = Storage::disk('public')->path('ffmpeg/arialuni.ttf'); 587 $font = Storage::disk('public')->path('ffmpeg/arialuni.ttf');
604 588
...@@ -607,7 +591,7 @@ class UserMakeVideo implements ShouldQueue ...@@ -607,7 +591,7 @@ class UserMakeVideo implements ShouldQueue
607 foreach ($components as $component) { 591 foreach ($components as $component) {
608 switch ($component->name){ 592 switch ($component->name){
609 case 'one_poem': 593 case 'one_poem':
610 - $content = $this->adminMakeVideo->poem->content; 594 + $content = $this->immerse->poem->content;
611 $text_file = $this->getTempPath('txt'); 595 $text_file = $this->getTempPath('txt');
612 file_put_contents($text_file, $content); 596 file_put_contents($text_file, $content);
613 597
...@@ -659,7 +643,7 @@ class UserMakeVideo implements ShouldQueue ...@@ -659,7 +643,7 @@ class UserMakeVideo implements ShouldQueue
659 'box=1:boxcolor=' . $text_bg_color . '@' . $opacity . '", '; 643 'box=1:boxcolor=' . $text_bg_color . '@' . $opacity . '", ';
660 break; 644 break;
661 case 'feel': 645 case 'feel':
662 - $content = $this->adminMakeVideo->feel; 646 + $content = $this->immerse->content;
663 $text_color = $component->text_color ?? 'white'; 647 $text_color = $component->text_color ?? 'white';
664 $text_bg_color = $component->text_bg_color ?? '0xd0cdcc'; 648 $text_bg_color = $component->text_bg_color ?? '0xd0cdcc';
665 $opacity = $component->opacity ? $component->opacity / 100 : '0.5'; 649 $opacity = $component->opacity ? $component->opacity / 100 : '0.5';
......
...@@ -24,34 +24,38 @@ class Immerse extends Model ...@@ -24,34 +24,38 @@ class Immerse extends Model
24 { 24 {
25 if ($url == '') return $url; 25 if ($url == '') return $url;
26 26
27 - if (Str::contains($url, '/storage/app/public/')) {
28 - $str = Str::of($url)->replace('/usr/local/nginx/html/OnePoem/storage/app/public/', '');
29 - return Storage::disk('public')->url($str);
30 - } else {
31 return Storage::disk('public')->url($url); 27 return Storage::disk('public')->url($url);
32 } 28 }
33 - }
34 29
35 public function getThumbnailAttribute($url) 30 public function getThumbnailAttribute($url)
36 { 31 {
37 32
38 - if (Str::contains($url, '/storage/app/public/')) { 33 + if ($url == '') return $url;
39 - $str = Str::of($url)->replace('/usr/local/nginx/html/OnePoem/storage/app/public/', ''); 34 +
40 - return Storage::disk('public')->url($str);
41 - } else {
42 return Storage::disk('public')->url($url); 35 return Storage::disk('public')->url($url);
43 } 36 }
44 - }
45 37
46 public function getBgmAttribute($url) 38 public function getBgmAttribute($url)
47 { 39 {
48 if ($url == '') return $url; 40 if ($url == '') return $url;
49 41
50 - if (Str::contains($url, '/storage/app/public/')) {
51 - $str = Str::of($url)->replace('/usr/local/nginx/html/OnePoem/storage/app/public/', '');
52 - return Storage::disk('public')->url($str);
53 - } else {
54 return Storage::disk('public')->url($url); 42 return Storage::disk('public')->url($url);
55 } 43 }
44 +
45 + public function poem()
46 + {
47 + return $this->hasOne(OnePoem::class,'id','poem_id');
48 + }
49 +
50 + public function temp()
51 + {
52 + return $this->hasOne(VideoTemp::class,'id','temp_id');
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];
56 } 60 }
57 } 61 }
......
...@@ -27,7 +27,7 @@ class CreateImmerseTable extends Migration ...@@ -27,7 +27,7 @@ class CreateImmerseTable extends Migration
27 $table->integer('collect')->default(0)->comment('收藏量'); 27 $table->integer('collect')->default(0)->comment('收藏量');
28 $table->integer('share')->default(0)->comment('分享量'); 28 $table->integer('share')->default(0)->comment('分享量');
29 $table->integer('comment')->default(0)->comment('评论数'); 29 $table->integer('comment')->default(0)->comment('评论数');
30 - $table->unsignedTinyInteger('is_self')->index()->default(1)->comment('自制=1,搬运=2'); 30 + $table->unsignedTinyInteger('state')->index()->default(1)->comment('0=正在合成,1=已完成,2=合成失败');
31 $table->unsignedTinyInteger('is_publish')->index()->default(1)->comment('草稿=0,发布=1'); 31 $table->unsignedTinyInteger('is_publish')->index()->default(1)->comment('草稿=0,发布=1');
32 $table->unsignedTinyInteger('is_check')->index()->default(0)->comment('审核通过=1,未通过=0'); 32 $table->unsignedTinyInteger('is_check')->index()->default(0)->comment('审核通过=1,未通过=0');
33 $table->timestamps(); 33 $table->timestamps();
......
...@@ -41,7 +41,7 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route ...@@ -41,7 +41,7 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->group(function (Route
41 $api->get('/user', 'UserController@user')->middleware('auth:sanctum'); 41 $api->get('/user', 'UserController@user')->middleware('auth:sanctum');
42 42
43 /** 上传作品 */ 43 /** 上传作品 */
44 - $api->get('/user', 'UserController@user')->middleware('auth:sanctum'); 44 + $api->get('/my/videos', 'UserController@videos')->middleware('auth:sanctum');
45 45
46 46
47 /** 临境 */ 47 /** 临境 */
......