Showing
4 changed files
with
76 additions
and
83 deletions
| ... | @@ -70,9 +70,10 @@ class DevFFmpeg extends Command | ... | @@ -70,9 +70,10 @@ class DevFFmpeg extends Command | 
| 70 | // $arr = json_decode($json,true); | 70 | // $arr = json_decode($json,true); | 
| 71 | // dd($arr); | 71 | // dd($arr); | 
| 72 | // dd(AdminMakeVideo::query()->find(1)->poem2()); | 72 | // dd(AdminMakeVideo::query()->find(1)->poem2()); | 
| 73 | - dd(AdminMakeVideo::query()->find(1)->poem2->verses->toArray()); | 73 | +// dd(AdminMakeVideo::query()->find(1)->poem2->verses->toArray()); | 
| 74 | - return 0; | 74 | +// return 0; | 
| 75 | - dd(AdminMakeVideo::query()->find(33)->temp->components->toArray()); | 75 | +// dd(AdminMakeVideo::query()->find(33)->temp->components->toArray()); | 
| 76 | + dd(AdminMakeVideo::query()->find(33)->temp->toArray()); | ||
| 76 | AdminMakeImmerse::dispatch(AdminMakeVideo::query()->find(33)->temp->components); | 77 | AdminMakeImmerse::dispatch(AdminMakeVideo::query()->find(33)->temp->components); | 
| 77 | 78 | ||
| 78 | 79 | ... | ... | 
app/Jobs/AdminMakeImmerse.bak
0 → 100644
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -44,75 +44,6 @@ class MakeVideo implements ShouldQueue | ... | @@ -44,75 +44,6 @@ class MakeVideo implements ShouldQueue | 
| 44 | $this->ffprobe = env('FFPROBE_CMD'); | 44 | $this->ffprobe = env('FFPROBE_CMD'); | 
| 45 | $this->output_width = 720; | 45 | $this->output_width = 720; | 
| 46 | $this->output_height = 1280; | 46 | $this->output_height = 1280; | 
| 47 | - | ||
| 48 | - $file = $this->getAbsolutePath($adminMakeVideo->video_url); | ||
| 49 | - // 分析视频 | ||
| 50 | - $media_info = $this->mediainfo($file); | ||
| 51 | - // 素材准备 | ||
| 52 | - $drawtext = $this->getTextContentString(); | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - $thumbnail = $this->getTempPath('.jpg','thumbnail'); | ||
| 57 | - if ($adminMakeVideo->thumbnail == 2){ | ||
| 58 | - // 截取中间帧作为视频封面 | ||
| 59 | - $frame = ceil($media_info['streams'][0]['nb_frames'] / 2); | ||
| 60 | - $cmd = $this->ffmpeg . ' -y ' . | ||
| 61 | - ' -i ' . escapeshellarg($file) . | ||
| 62 | - ' -filter_complex "[0:v]select=\'eq(n,' . $frame . ')\'[img]" ' . | ||
| 63 | - ' -map [img]'. | ||
| 64 | - ' -frames:v 1 -s ' . $this->output_width . 'x' . $this->output_height . ' -preset superfast ' . | ||
| 65 | - escapeshellarg($this->getAbsolutePath($thumbnail)); | ||
| 66 | - if (!$this->execmd($cmd)) return ; | ||
| 67 | - }else{ | ||
| 68 | - // 手动上传封面 | ||
| 69 | - $origin_thumbnail = Storage::disk('public')->path($adminMakeVideo->thumbnail_url); | ||
| 70 | - // 将封面分辨率改为指定分辨率 | ||
| 71 | - $cmd = $this->ffmpeg . ' -y ' . | ||
| 72 | - ' -i ' . escapeshellarg($origin_thumbnail) . | ||
| 73 | - '-s ' . $this->output_width . 'x' . $this->output_height . ' -preset superfast ' . | ||
| 74 | - escapeshellarg($this->getAbsolutePath($thumbnail)); | ||
| 75 | - if (!$this->execmd($cmd)) return ; | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - $output = $this->getTempPath('.mp4','video'); | ||
| 79 | - $cmd = $this->ffmpeg . ' -y '. | ||
| 80 | - ' -i ' . escapeshellarg($file). | ||
| 81 | - ' -i ' . escapeshellarg($watermark). | ||
| 82 | - $audio_input . | ||
| 83 | - ' -filter_complex "[0:v]scale=' . $this->output_width . ':' . $this->output_height . ',' . $drawtext . | ||
| 84 | - ' [text];[text]'. | ||
| 85 | - ' [1:v]overlay=20:20[v]" ' . | ||
| 86 | - ' -map [v] -map '. $audio_filter . | ||
| 87 | - ' -c:v libx264 -bt 256k -r 25' . | ||
| 88 | - ' -ar 44100 -ac 2 -qmin 30 -qmax 60 -profile:v baseline -preset fast ' . | ||
| 89 | - escapeshellarg($this->getAbsolutePath($output)); | ||
| 90 | - | ||
| 91 | - if (!$this->execmd($cmd)) return ; | ||
| 92 | - | ||
| 93 | - $video_info = $this->mediainfo($this->getAbsolutePath($output)); | ||
| 94 | - Immerse::query()->create([ | ||
| 95 | - 'user_id' => 1, | ||
| 96 | - 'title' => '', | ||
| 97 | - 'weather' => $adminMakeVideo->weather, | ||
| 98 | - 'huangli' => $adminMakeVideo->huangli, | ||
| 99 | - 'content' => $adminMakeVideo->feel, | ||
| 100 | - 'location' => $adminMakeVideo->location, | ||
| 101 | - 'longitude' => $adminMakeVideo->longitude, | ||
| 102 | - 'latitude' => $adminMakeVideo->latitude, | ||
| 103 | - 'url' => $output, | ||
| 104 | - 'type' => $adminMakeVideo->type == 1 ? 2 : 1, | ||
| 105 | - 'upload_file' => '', | ||
| 106 | - 'duration' => $video_info['format']['duration'], | ||
| 107 | - 'size' => $video_info['format']['size'], | ||
| 108 | - 'origin_video_url' => $this->adminMakeVideo->video_url, | ||
| 109 | - 'origin_image_url' => '', | ||
| 110 | - 'poem_id' => $this->adminMakeVideo->poem_id, | ||
| 111 | - 'temp_id' => $this->adminMakeVideo->temp_id, | ||
| 112 | - 'thumbnail' => $thumbnail, | ||
| 113 | - 'state' => 1, | ||
| 114 | - 'bgm' => $is_bgm ? $bgm : '', | ||
| 115 | - ]); | ||
| 116 | } | 47 | } | 
| 117 | 48 | ||
| 118 | /** | 49 | /** | 
| ... | @@ -127,23 +58,24 @@ class MakeVideo implements ShouldQueue | ... | @@ -127,23 +58,24 @@ class MakeVideo implements ShouldQueue | 
| 127 | $this->media_info = $this->mediaInfo($file); | 58 | $this->media_info = $this->mediaInfo($file); | 
| 128 | 59 | ||
| 129 | // 准备素材 | 60 | // 准备素材 | 
| 61 | + $watermark = $this->getAbsolutePath('images/LOGO_eng.png'); | ||
| 130 | 62 | ||
| 131 | // 组装文字参数 | 63 | // 组装文字参数 | 
| 132 | $drawtext = $this->getTextContentString(); | 64 | $drawtext = $this->getTextContentString(); | 
| 133 | 65 | ||
| 134 | - // 合成视频 | 66 | + // 判断双轨 没有则制作空轨 | 
| 135 | - | 67 | + $is_bgm = $this->adminMakeVideo->temp->bg_music == 1; //是否手动上传背景音 | 
| 136 | - if ($this->media_info['format']['nb_streams'] >= 2) { | 68 | + if ($this->media_info['format']['nb_streams'] >= 2) { /** 音频视频轨都有 */ | 
| 137 | - /** 音频视频轨都有 */ | ||
| 138 | if ($is_bgm) { | 69 | if ($is_bgm) { | 
| 139 | // 有背景音 融合 | 70 | // 有背景音 融合 | 
| 140 | $audio = $this->getAbsolutePath($this->getTempPath('.mp3','audio')); | 71 | $audio = $this->getAbsolutePath($this->getTempPath('.mp3','audio')); | 
| 72 | + $bgm = $this->getAbsolutePath($this->adminMakeVideo->temp->bgm_url); | ||
| 141 | $cmd = $this->ffmpeg . | 73 | $cmd = $this->ffmpeg . | 
| 142 | ' -y -i ' . escapeshellarg($file) . | 74 | ' -y -i ' . escapeshellarg($file) . | 
| 143 | ' -y -i ' . escapeshellarg($bgm) . | 75 | ' -y -i ' . escapeshellarg($bgm) . | 
| 144 | ' -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ' . | 76 | ' -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ' . | 
| 145 | '-ar 48000 -ab 64k ' . escapeshellarg($audio); | 77 | '-ar 48000 -ab 64k ' . escapeshellarg($audio); | 
| 146 | - if (!$this->execmd($cmd)) return; | 78 | + if (!$this->execCmd($cmd)) return; | 
| 147 | 79 | ||
| 148 | $audio_input = ' -i ' . escapeshellarg($audio); | 80 | $audio_input = ' -i ' . escapeshellarg($audio); | 
| 149 | $audio_filter = '2:a'; | 81 | $audio_filter = '2:a'; | 
| ... | @@ -152,25 +84,25 @@ class MakeVideo implements ShouldQueue | ... | @@ -152,25 +84,25 @@ class MakeVideo implements ShouldQueue | 
| 152 | $audio_input = ''; | 84 | $audio_input = ''; | 
| 153 | $audio_filter = '0:a'; | 85 | $audio_filter = '0:a'; | 
| 154 | } | 86 | } | 
| 155 | - } elseif ($media_info['format']['nb_streams'] == 1) { | 87 | + } elseif ($this->media_info['format']['nb_streams'] == 1) { /** 只有视频轨 */ | 
| 156 | - /** 只有视频轨 */ | ||
| 157 | // 生成一段无声音频 | 88 | // 生成一段无声音频 | 
| 158 | $audio = $this->getAbsolutePath($this->getTempPath('.mp3','audio')); | 89 | $audio = $this->getAbsolutePath($this->getTempPath('.mp3','audio')); | 
| 159 | $cmd = $this->ffmpeg . | 90 | $cmd = $this->ffmpeg . | 
| 160 | - ' -y -f lavfi -i aevalsrc=0:duration=' . escapeshellarg($media_info['format']['duration']) . | 91 | + ' -y -f lavfi -i aevalsrc=0:duration=' . escapeshellarg($this->media_info['format']['duration']) . | 
| 161 | ' -ar 48000 -ab 64k ' . escapeshellarg($audio); | 92 | ' -ar 48000 -ab 64k ' . escapeshellarg($audio); | 
| 162 | - if (!$this->execmd($cmd)) return; | 93 | + if (!$this->execCmd($cmd)) return; | 
| 163 | 94 | ||
| 164 | if ($is_bgm) { | 95 | if ($is_bgm) { | 
| 165 | // 有背景音 融合 | 96 | // 有背景音 融合 | 
| 166 | $audio_empty = $audio; | 97 | $audio_empty = $audio; | 
| 167 | - $audio = $this->getAbsolutePath($this->getTempPath('.mp3')); | 98 | + $bgm = $this->getAbsolutePath($this->adminMakeVideo->temp->bgm_url); | 
| 99 | + $audio = $this->getAbsolutePath($this->getTempPath('.mp3','audio')); | ||
| 168 | $cmd = $this->ffmpeg . | 100 | $cmd = $this->ffmpeg . | 
| 169 | ' -y -i ' . escapeshellarg($audio_empty) . | 101 | ' -y -i ' . escapeshellarg($audio_empty) . | 
| 170 | ' -y -i ' . escapeshellarg($bgm) . | 102 | ' -y -i ' . escapeshellarg($bgm) . | 
| 171 | ' -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ' . | 103 | ' -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ' . | 
| 172 | '-ar 48000 -ab 64k ' . escapeshellarg($audio); | 104 | '-ar 48000 -ab 64k ' . escapeshellarg($audio); | 
| 173 | - if (!$this->execmd($cmd)) return; | 105 | + if (!$this->execCmd($cmd)) return; | 
| 174 | } | 106 | } | 
| 175 | $audio_input = ' -i ' . escapeshellarg($audio); | 107 | $audio_input = ' -i ' . escapeshellarg($audio); | 
| 176 | $audio_filter = '2:a'; | 108 | $audio_filter = '2:a'; | 
| ... | @@ -181,8 +113,68 @@ class MakeVideo implements ShouldQueue | ... | @@ -181,8 +113,68 @@ class MakeVideo implements ShouldQueue | 
| 181 | } | 113 | } | 
| 182 | 114 | ||
| 183 | // 制作封面图 | 115 | // 制作封面图 | 
| 116 | + $thumbnail = $this->getTempPath('.jpg','thumbnail'); | ||
| 117 | + if ($this->adminMakeVideo->thumbnail == 2){ | ||
| 118 | + // 截取中间帧作为视频封面 | ||
| 119 | + $frame = ceil($this->media_info['streams'][0]['nb_frames'] / 2); | ||
| 120 | + $cmd = $this->ffmpeg . ' -y ' . | ||
| 121 | + ' -i ' . escapeshellarg($file) . | ||
| 122 | + ' -filter_complex "[0:v]select=\'eq(n,' . $frame . ')\'[img]" ' . | ||
| 123 | + ' -map [img]'. | ||
| 124 | + ' -frames:v 1 -s ' . $this->output_width . 'x' . $this->output_height . ' -preset superfast ' . | ||
| 125 | + escapeshellarg($this->getAbsolutePath($thumbnail)); | ||
| 126 | + if (!$this->execCmd($cmd)) return ; | ||
| 127 | + }else{ | ||
| 128 | + // 手动上传封面 | ||
| 129 | + $origin_thumbnail = $this->getAbsolutePath($this->adminMakeVideo->thumbnail_url); | ||
| 130 | + // 将封面分辨率改为指定分辨率 | ||
| 131 | + $cmd = $this->ffmpeg . ' -y ' . | ||
| 132 | + ' -i ' . escapeshellarg($origin_thumbnail) . | ||
| 133 | + '-s ' . $this->output_width . 'x' . $this->output_height . ' -preset superfast ' . | ||
| 134 | + escapeshellarg($this->getAbsolutePath($thumbnail)); | ||
| 135 | + if (!$this->execCmd($cmd)) return ; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + // 合成视频 | ||
| 139 | + $output = $this->getTempPath('.mp4','video'); | ||
| 140 | + $cmd = $this->ffmpeg . ' -y '. | ||
| 141 | + ' -i ' . escapeshellarg($file). | ||
| 142 | + ' -i ' . escapeshellarg($watermark). | ||
| 143 | + $audio_input . | ||
| 144 | + ' -filter_complex "[0:v]scale=' . $this->output_width . ':' . $this->output_height . ',' . $drawtext . | ||
| 145 | + ' [text];[text]'. | ||
| 146 | + ' [1:v]overlay=20:20[v]" ' . | ||
| 147 | + ' -map [v] -map '. $audio_filter . | ||
| 148 | + ' -c:v libx264 -bt 256k -r 25' . | ||
| 149 | + ' -ar 44100 -ac 2 -qmin 30 -qmax 60 -profile:v baseline -preset fast ' . | ||
| 150 | + escapeshellarg($this->getAbsolutePath($output)); | ||
| 151 | + | ||
| 152 | + if (!$this->execCmd($cmd)) return ; | ||
| 184 | 153 | ||
| 185 | // 分析视频 入库 | 154 | // 分析视频 入库 | 
| 155 | + $video_info = $this->mediainfo($this->getAbsolutePath($output)); | ||
| 156 | + Immerse::query()->create([ | ||
| 157 | + 'user_id' => 1, | ||
| 158 | + 'title' => '', | ||
| 159 | + 'weather' => $this->adminMakeVideo->weather, | ||
| 160 | + 'huangli' => $this->adminMakeVideo->huangli, | ||
| 161 | + 'content' => $this->adminMakeVideo->feel, | ||
| 162 | + 'location' => $this->adminMakeVideo->location, | ||
| 163 | + 'longitude' => $this->adminMakeVideo->longitude, | ||
| 164 | + 'latitude' => $this->adminMakeVideo->latitude, | ||
| 165 | + 'url' => $output, | ||
| 166 | + 'type' => $this->adminMakeVideo->type == 1 ? 2 : 1, | ||
| 167 | + 'upload_file' => '', | ||
| 168 | + 'duration' => $video_info['format']['duration'], | ||
| 169 | + 'size' => $video_info['format']['size'], | ||
| 170 | + 'origin_video_url' => $this->adminMakeVideo->video_url, | ||
| 171 | + 'origin_image_url' => '', | ||
| 172 | + 'poem_id' => $this->adminMakeVideo->poem_id, | ||
| 173 | + 'temp_id' => $this->adminMakeVideo->temp_id, | ||
| 174 | + 'thumbnail' => $thumbnail, | ||
| 175 | + 'state' => 1, | ||
| 176 | + 'bgm' => $is_bgm ? $bgm : '', | ||
| 177 | + ]); | ||
| 186 | } | 178 | } | 
| 187 | 179 | ||
| 188 | public function getAbsolutePath($path) | 180 | public function getAbsolutePath($path) | ... | ... | 
- 
Please register or login to post a comment