Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-Server
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
李帅
2022-12-27 17:52:55 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0a3d0b66b01aaa344f132c669b3e01d1e0896c9c
0a3d0b66
1 parent
8fcc268d
1.微调一下接口,打印参数
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
35 deletions
app/Admin/Controllers/ImmerseController.php
app/Jobs/AdminMakeImmerse.php
app/Jobs/UserMakeImmerse.php
app/Admin/Controllers/ImmerseController.php
View file @
0a3d0b6
...
...
@@ -30,7 +30,7 @@ class ImmerseController extends AdminController
return
Grid
::
make
(
new
Immerse
(),
function
(
Grid
$grid
)
{
// 去掉新增和删除按钮
$grid
->
disableCreateButton
();
$grid
->
disableFilterButton
();
//
$grid->disableFilterButton();
$grid
->
model
()
->
where
(
'user_id'
,
'='
,
1
);
...
...
@@ -55,12 +55,11 @@ class ImmerseController extends AdminController
$grid
->
column
(
'temp_id'
);
$grid
->
column
(
'thumbnail'
)
->
image
();
$grid
->
column
(
'bgm'
)
->
display
(
function
(
$url
){
if
(
$url
==
''
)
return
"无"
;
if
(
Str
::
of
(
$url
)
->
contains
(
'.mp3'
))
return
"<a target='_blank' href='"
.
$url
.
"'>查看</a>"
;
elseif
(
Str
::
of
(
$url
)
->
contains
(
'.aac'
))
return
"<a target='_blank' href='"
.
$url
.
"'>下载</a>"
;
else
return
"
无效路径
"
;
return
"
<a target='_blank' href='"
.
$url
.
"'>下载</a>
"
;
});
$grid
->
column
(
'created_at'
);
$grid
->
column
(
'updated_at'
)
->
sortable
();
...
...
app/Jobs/AdminMakeImmerse.php
View file @
0a3d0b6
...
...
@@ -71,7 +71,7 @@ class AdminMakeImmerse implements ShouldQueue
/** 音频视频轨都有 */
if
(
$is_bgm
)
{
// 有背景音 融合
$audio
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$cmd
=
$this
->
ffmpeg
.
' -y -i '
.
escapeshellarg
(
$file
)
.
' -y -i '
.
escapeshellarg
(
$bgm
)
.
...
...
@@ -89,7 +89,7 @@ class AdminMakeImmerse implements ShouldQueue
}
elseif
(
$media_info
[
'format'
][
'nb_streams'
]
==
1
)
{
/** 只有视频轨 */
// 生成一段无声音频
$audio
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$cmd
=
$this
->
ffmpeg
.
' -y -f lavfi -i aevalsrc=0:duration='
.
escapeshellarg
(
$media_info
[
'format'
][
'duration'
])
.
' -ar 48000 -ab 64k '
.
escapeshellarg
(
$audio
);
...
...
@@ -114,7 +114,7 @@ class AdminMakeImmerse implements ShouldQueue
return
;
}
$thumbnail
=
$this
->
getTempPath
(
'.jpg'
,
false
);
$thumbnail
=
$this
->
getTempPath
(
'.jpg'
,
'thumbnail'
);
if
(
$adminMakeVideo
->
thumbnail
==
2
){
// 截取中间帧作为视频封面
$frame
=
ceil
(
$media_info
[
'streams'
][
0
][
'nb_frames'
]
/
2
);
...
...
@@ -136,7 +136,7 @@ class AdminMakeImmerse implements ShouldQueue
if
(
!
$this
->
execmd
(
$cmd
))
return
;
}
$output
=
$this
->
getTempPath
(
'.mp4'
,
false
);
$output
=
$this
->
getTempPath
(
'.mp4'
,
'video'
);
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$file
)
.
' -i '
.
escapeshellarg
(
$watermark
)
.
...
...
@@ -180,7 +180,7 @@ class AdminMakeImmerse implements ShouldQueue
if
(
$this
->
adminMakeVideo
->
type
==
2
&&
!
$is_bgm
){
// 没有背景音,单图一张,输出为单图。
$output
=
$this
->
getTempPath
(
'.png'
,
false
);
$output
=
$this
->
getTempPath
(
'.png'
,
'thumbnail'
);
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$image
)
.
' -i '
.
escapeshellarg
(
$watermark
)
.
...
...
@@ -191,7 +191,7 @@ class AdminMakeImmerse implements ShouldQueue
$thumbnail
=
$output
;
}
else
{
// 有背景音 单图合成视频,时长为音频时长,音频加入背景音
$output
=
$this
->
getTempPath
(
'.mp4'
,
false
);
$output
=
$this
->
getTempPath
(
'.mp4'
,
'video'
);
// 分析背景音
$mediainfo
=
$this
->
mediainfo
(
$bgm
);
...
...
@@ -211,7 +211,7 @@ class AdminMakeImmerse implements ShouldQueue
escapeshellarg
(
$this
->
getAbsolutePath
(
$output
));
if
(
!
$this
->
execmd
(
$cmd
))
return
;
$thumbnail
=
$this
->
getTempPath
(
'.jpg'
,
false
);
$thumbnail
=
$this
->
getTempPath
(
'.jpg'
,
'thumbnail'
);
if
(
$adminMakeVideo
->
thumbnail
==
2
){
// 将封面分辨率改为指定分辨率
$cmd
=
$this
->
ffmpeg
.
' -y '
.
...
...
@@ -325,14 +325,13 @@ class AdminMakeImmerse implements ShouldQueue
/**
* 获取输出临时文件名
* @param string $ext
* @param
bool $is_temp
* @param
string $dir
* @return string
*/
public
function
getTempPath
(
$ext
=
'.mp4'
,
$
is_temp
=
true
)
public
function
getTempPath
(
$ext
=
'.mp4'
,
$
dir
=
'video'
)
{
$filename
=
"/output_"
.
time
()
.
rand
(
0
,
10000
);
$prefix
=
$is_temp
?
'temp/'
:
'video/'
;
$hash_hex
=
md5
(
$filename
);
// 16进制表示的字符串一共32字节,表示16个二进制字节。
// 前16个字符用来第一级求摸,后16个用做第二级
...
...
@@ -340,7 +339,7 @@ class AdminMakeImmerse implements ShouldQueue
$hash_hex_l2
=
substr
(
$hash_hex
,
8
,
8
);
$dir_l1
=
hexdec
(
$hash_hex_l1
)
%
256
;
$dir_l2
=
hexdec
(
$hash_hex_l2
)
%
512
;
$dir
=
$
prefix
.
$dir_l1
.
'/'
.
$dir_l2
;
$dir
=
$
dir
.
'/'
.
$dir_l1
.
'/'
.
$dir_l2
;
if
(
!
Storage
::
disk
(
'public'
)
->
exists
(
$dir
))
Storage
::
disk
(
'public'
)
->
makeDirectory
(
$dir
);
...
...
@@ -373,7 +372,7 @@ class AdminMakeImmerse implements ShouldQueue
case
'every_poem'
:
case
'one_poem'
:
$content
=
$this
->
adminMakeVideo
->
poem
->
content
;
$text_file
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.txt'
));
$text_file
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
...
...
@@ -389,9 +388,11 @@ class AdminMakeImmerse implements ShouldQueue
break
;
case
'weather'
:
$content
=
$this
->
adminMakeVideo
->
weather
;
$text_file
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
'text
='
.
escapeshellarg
(
$content
)
.
':'
.
'text
file='
.
escapeshellarg
(
$text_file
)
.
':'
.
'fontsize='
.
$this
->
calcFontSize
(
$component
->
font_size
)
.
':'
.
'fontcolor='
.
$text_color
.
'@'
.
$opacity
.
':'
.
'x='
.
escapeshellarg
(
VideoTemp
::
POSITION_FFMPEG
[
$component
->
position
][
0
])
.
':'
.
...
...
@@ -403,9 +404,11 @@ class AdminMakeImmerse implements ShouldQueue
break
;
case
'date'
:
$content
=
Carbon
::
now
()
->
format
(
'Y年m月d日H时'
);
$text_file
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
'text
='
.
escapeshellarg
(
$content
)
.
':'
.
'text
file='
.
escapeshellarg
(
$text_file
)
.
':'
.
'fontsize='
.
$this
->
calcFontSize
(
$component
->
font_size
)
.
':'
.
'fontcolor='
.
$text_color
.
'@'
.
$opacity
.
':'
.
'x='
.
escapeshellarg
(
VideoTemp
::
POSITION_FFMPEG
[
$component
->
position
][
0
])
.
':'
.
...
...
@@ -416,9 +419,11 @@ class AdminMakeImmerse implements ShouldQueue
break
;
case
'feel'
:
$content
=
$this
->
adminMakeVideo
->
feel
?:
'读此一言,仿佛身临其境。'
;
$text_file
=
$this
->
getAbsolutePath
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
'text
='
.
escapeshellarg
(
$content
)
.
':'
.
'text
file='
.
escapeshellarg
(
$text_file
)
.
':'
.
'fontsize='
.
$this
->
calcFontSize
(
$component
->
font_size
)
.
':'
.
'fontcolor='
.
$text_color
.
'@'
.
$opacity
.
':'
.
'x='
.
escapeshellarg
(
VideoTemp
::
POSITION_FFMPEG
[
$component
->
position
][
0
])
.
':'
.
...
...
app/Jobs/UserMakeImmerse.php
View file @
0a3d0b6
...
...
@@ -74,7 +74,7 @@ class UserMakeImmerse implements ShouldQueue
// 音频还取之前的封面。
$thumbnail
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
immerse
->
thumbnail
);
$video
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp4'
,
false
));
$video
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp4'
,
'video'
));
if
(
$this
->
immerse
->
origin_video_url
==
''
||
$this
->
immerse
->
origin_video_url
==
null
)
{
// 原官方临境是图片
...
...
@@ -83,7 +83,7 @@ class UserMakeImmerse implements ShouldQueue
if
(
$this
->
immerse
->
bgm
==
''
||
$this
->
immerse
->
bgm
==
null
)
{
$audio
=
$upload_file
;
}
else
{
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$bgm
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
immerse
->
bgm
);
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$upload_file
)
.
...
...
@@ -120,7 +120,7 @@ class UserMakeImmerse implements ShouldQueue
//用户录音超长,截取用户录音
if
(
$mediainfo
[
'format'
][
'duration'
]
>
$origin_mediainfo
[
'format'
][
'duration'
])
{
if
(
$this
->
immerse
->
bgm
==
''
||
$this
->
immerse
->
bgm
==
null
)
{
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$upload_file
)
.
' -ss 0 -t '
.
escapeshellarg
(
$origin_mediainfo
[
'format'
][
'duration'
])
.
...
...
@@ -128,7 +128,7 @@ class UserMakeImmerse implements ShouldQueue
if
(
!
$this
->
execmd
(
$cmd
))
return
;
}
else
{
$bgm
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
immerse
->
bgm
);
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$upload_file
)
.
' -i '
.
escapeshellarg
(
$bgm
)
.
...
...
@@ -141,7 +141,7 @@ class UserMakeImmerse implements ShouldQueue
if
(
$this
->
immerse
->
bgm
==
''
||
$this
->
immerse
->
bgm
==
null
)
{
$audio
=
$upload_file
;
}
else
{
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
));
$audio
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp3'
,
'audio'
));
$bgm
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
immerse
->
bgm
);
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$upload_file
)
.
...
...
@@ -209,7 +209,7 @@ class UserMakeImmerse implements ShouldQueue
// 截取中间帧作为视频封面
$frame
=
ceil
(
$mediainfo
[
'streams'
][
0
][
'nb_frames'
]
/
2
);
$thumbnail
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.jpg'
,
false
));
$thumbnail
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.jpg'
,
'thumbnail'
));
$cmd
=
$this
->
ffmpeg
.
' -y '
.
' -i '
.
escapeshellarg
(
$upload_file
)
.
' -i '
.
escapeshellarg
(
$watermark
)
.
...
...
@@ -219,7 +219,7 @@ class UserMakeImmerse implements ShouldQueue
escapeshellarg
(
$thumbnail
);
if
(
!
$this
->
execmd
(
$cmd
))
return
;
$video
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp4'
,
false
));
$video
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.mp4'
,
'video'
));
// 没有背景音
if
(
$this
->
immerse
->
bgm
==
''
||
$this
->
immerse
->
bgm
==
null
)
{
$cmd
=
$this
->
ffmpeg
.
' -y '
.
...
...
@@ -325,14 +325,13 @@ class UserMakeImmerse implements ShouldQueue
/**
* 获取输出临时文件名
* @param string $ext
* @param
bool $is_temp
* @param
string $dir
* @return string
*/
public
function
getTempPath
(
$ext
=
'.mp4'
,
$is_temp
=
true
)
public
function
getTempPath
(
$ext
=
'.mp4'
,
$dir
=
'video'
)
{
$filename
=
"/output_"
.
time
()
.
rand
(
0
,
10000
);
$prefix
=
$is_temp
?
'temp/'
:
'video/'
;
$hash_hex
=
md5
(
$filename
);
// 16进制表示的字符串一共32字节,表示16个二进制字节。
// 前16个字符用来第一级求摸,后16个用做第二级
...
...
@@ -340,7 +339,7 @@ class UserMakeImmerse implements ShouldQueue
$hash_hex_l2
=
substr
(
$hash_hex
,
8
,
8
);
$dir_l1
=
hexdec
(
$hash_hex_l1
)
%
256
;
$dir_l2
=
hexdec
(
$hash_hex_l2
)
%
512
;
$dir
=
$
prefix
.
$dir_l1
.
'/'
.
$dir_l2
;
$dir
=
$
dir
.
'/'
.
$dir_l1
.
'/'
.
$dir_l2
;
if
(
!
Storage
::
disk
(
'public'
)
->
exists
(
$dir
))
Storage
::
disk
(
'public'
)
->
makeDirectory
(
$dir
);
...
...
@@ -477,7 +476,7 @@ class UserMakeImmerse implements ShouldQueue
$white
=
imagecolorallocate
(
$wp
,
0xDC
,
0x14
,
0x3C
);
//fixme 字体颜色
imagettftext
(
$wp
,
20
,
0
,
75
,
240
,
$white
,
$font
,
$signature
);
$dst
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.png'
));
$dst
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.png'
,
'temp'
));
imagepng
(
$wp
,
$dst
);
if
(
is_resource
(
$end_wallpaper
))
imagedestroy
(
$end_wallpaper
);
if
(
is_resource
(
$_img
))
imagedestroy
(
$_img
);
...
...
@@ -504,7 +503,7 @@ class UserMakeImmerse implements ShouldQueue
case
'every_poem'
:
case
'one_poem'
:
$content
=
$this
->
immerse
->
poem
->
content
;
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
));
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$text_color
=
$component
->
text_color
??
'white'
;
...
...
@@ -524,7 +523,7 @@ class UserMakeImmerse implements ShouldQueue
break
;
case
'weather'
:
$content
=
$this
->
immerse
->
weather
;
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
));
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
...
...
@@ -540,9 +539,11 @@ class UserMakeImmerse implements ShouldQueue
break
;
case
'date'
:
$content
=
Carbon
::
now
()
->
format
(
'Y年m月d日H时'
);
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
'text
='
.
escapeshellarg
(
$content
)
.
':'
.
'text
file='
.
escapeshellarg
(
$text_file
)
.
':'
.
'fontsize='
.
$this
->
calcFontSize
(
$component
->
font_size
)
.
':'
.
'fontcolor='
.
$text_color
.
'@'
.
$opacity
.
':'
.
'x='
.
escapeshellarg
(
VideoTemp
::
POSITION_FFMPEG
[
$component
->
position
][
0
])
.
':'
.
...
...
@@ -553,9 +554,11 @@ class UserMakeImmerse implements ShouldQueue
break
;
case
'feel'
:
$content
=
$this
->
immerse
->
content
;
$text_file
=
Storage
::
disk
(
'public'
)
->
path
(
$this
->
getTempPath
(
'.txt'
,
'text'
));
file_put_contents
(
$text_file
,
$content
);
$drawtext
.=
'drawtext="'
.
'fontfile='
.
escapeshellarg
(
$font_file
)
.
':'
.
'text
='
.
escapeshellarg
(
$content
)
.
':'
.
'text
file='
.
escapeshellarg
(
$text_file
)
.
':'
.
'fontsize='
.
$this
->
calcFontSize
(
$component
->
font_size
)
.
':'
.
'fontcolor='
.
$text_color
.
'@'
.
$opacity
.
':'
.
'x='
.
escapeshellarg
(
VideoTemp
::
POSITION_FFMPEG
[
$component
->
position
][
0
])
.
':'
.
...
...
Please
register
or
login
to post a comment