Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
17f61a23
Commit
17f61a23
authored
Nov 12, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
参数处理
parent
0dbf312b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
236 additions
and
104 deletions
+236
-104
YzgFileService.java
.../main/java/com/yanzuoguang/cloud/file/YzgFileService.java
+1
-1
YzgFileConvertBase.java
...ava/com/yanzuoguang/cloud/file/vo/YzgFileConvertBase.java
+96
-0
YzgFileConvertVideoFirstReqVo.java
...zuoguang/cloud/file/vo/YzgFileConvertVideoFirstReqVo.java
+54
-0
YzgFileVideoImageInfoVo.java
...om/yanzuoguang/cloud/file/vo/YzgFileVideoImageInfoVo.java
+10
-10
YzgFileVideoImageItemReqVo.java
...yanzuoguang/cloud/file/vo/YzgFileVideoImageItemReqVo.java
+12
-77
YzgFileVideoImageReqVo.java
...com/yanzuoguang/cloud/file/vo/YzgFileVideoImageReqVo.java
+7
-7
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+56
-9
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileService.java
View file @
17f61a23
...
...
@@ -51,7 +51,7 @@ public interface YzgFileService {
*
* @param req
*/
void
convertVideoFirst
(
YzgFile
MoveItem
ReqVo
req
);
void
convertVideoFirst
(
YzgFile
ConvertVideoFirst
ReqVo
req
);
/**
* 转换视频质量
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/vo/YzgFileConvertBase.java
0 → 100644
View file @
17f61a23
package
com
.
yanzuoguang
.
cloud
.
file
.
vo
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* 转换基础类
*
* @author 颜佐光
*/
public
class
YzgFileConvertBase
{
/**
* 高质量品质
*/
public
static
final
YzgFileConvertBase
VIDEO_TYPE_HIGH
=
new
YzgFileConvertBase
(
0.01f
,
0.01f
,
1920
,
1080
,
8311136
);
/**
* 常规品质
*/
public
static
final
YzgFileConvertBase
VIDEO_TYPE_COMMON
=
new
YzgFileConvertBase
(
0.01f
,
0.01f
,
800
,
600
,
600000
);
/**
* 低质量品质
*/
public
static
final
YzgFileConvertBase
VIDEO_TYPE_LOW
=
new
YzgFileConvertBase
(
0.01f
,
0.01f
,
960
,
0
,
2955811
);
@ApiModelProperty
(
notes
=
"压缩尺寸比例,默认为1,范围在0~1之间."
)
protected
float
size
=
1
f
;
@ApiModelProperty
(
notes
=
"质量压缩比例,默认为1,范围在0~1之间."
)
protected
float
quote
=
1
f
;
@ApiModelProperty
(
notes
=
"最低宽度,如: 1920*1080中的1920."
)
protected
int
width
=
0
;
@ApiModelProperty
(
notes
=
"最低高度,如: 1920*1080中的1080."
)
protected
int
height
=
0
;
@ApiModelProperty
(
notes
=
"最低质量值"
)
protected
int
bitrate
=
0
;
public
YzgFileConvertBase
()
{
}
public
YzgFileConvertBase
(
float
size
,
float
quote
,
int
width
,
int
height
,
int
bitrate
)
{
this
.
size
=
size
;
this
.
quote
=
quote
;
this
.
width
=
width
;
this
.
height
=
height
;
this
.
bitrate
=
bitrate
;
}
public
float
getSize
()
{
return
size
;
}
public
void
setSize
(
float
size
)
{
this
.
size
=
size
;
}
public
float
getQuote
()
{
return
quote
;
}
public
void
setQuote
(
float
quote
)
{
this
.
quote
=
quote
;
}
public
int
getWidth
()
{
return
width
;
}
public
void
setWidth
(
int
width
)
{
this
.
width
=
width
;
}
public
int
getHeight
()
{
return
height
;
}
public
void
setHeight
(
int
height
)
{
this
.
height
=
height
;
}
public
int
getBitrate
()
{
return
bitrate
;
}
public
void
setBitrate
(
int
bitrate
)
{
this
.
bitrate
=
bitrate
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/vo/YzgFileConvertVideoFirstReqVo.java
0 → 100644
View file @
17f61a23
package
com
.
yanzuoguang
.
cloud
.
file
.
vo
;
import
com.yanzuoguang.util.vo.BaseVo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* 转换文件首帧信息
*
* @author 颜佐光
*/
@ApiModel
(
description
=
"转换文件首帧信息"
)
public
class
YzgFileConvertVideoFirstReqVo
extends
BaseVo
{
/**
* 转换文件的来源路径,当目标路径存在时,则认为已经移动成功
*/
@ApiModelProperty
(
notes
=
"移动文件的来源路径,当目标路径存在时,则认为已经移动成功"
,
position
=
1000
)
private
String
from
;
/**
* 转换文件的目标路径,建议扩展名为jpg
*/
@ApiModelProperty
(
notes
=
"转换文件的目标路径,建议扩展名为jpg"
,
position
=
1010
)
private
String
to
;
public
YzgFileConvertVideoFirstReqVo
()
{
}
public
YzgFileConvertVideoFirstReqVo
(
String
from
)
{
this
.
from
=
from
;
}
public
YzgFileConvertVideoFirstReqVo
(
String
from
,
String
to
)
{
this
.
from
=
from
;
this
.
to
=
to
;
}
public
String
getFrom
()
{
return
from
;
}
public
void
setFrom
(
String
from
)
{
this
.
from
=
from
;
}
public
String
getTo
()
{
return
to
;
}
public
void
setTo
(
String
to
)
{
this
.
to
=
to
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/vo/YzgFileVideoImageInfoVo.java
View file @
17f61a23
...
...
@@ -13,51 +13,51 @@ public class YzgFileVideoImageInfoVo extends YzgFileBaseVo {
* 分辨率x,如: 1920*1080中的1920.
*/
@ApiModelProperty
(
notes
=
"分辨率x,如: 1920*1080中的1920."
)
private
Long
width
;
private
Integer
width
;
/**
* 分辨率y,如: 1920*1080中的1080.
*/
@ApiModelProperty
(
notes
=
"分辨率y,如: 1920*1080中的1080."
)
private
Long
height
;
private
Integer
height
;
/**
* 质量
*/
@ApiModelProperty
(
notes
=
"质量"
,
position
=
1040
)
private
Long
bitrate
;
private
Integer
bitrate
;
public
YzgFileVideoImageInfoVo
()
{
}
public
YzgFileVideoImageInfoVo
(
String
server
,
String
display
,
long
size
,
String
mime
,
int
type
,
Long
width
,
Long
height
,
Long
bitrate
)
{
public
YzgFileVideoImageInfoVo
(
String
server
,
String
display
,
long
size
,
String
mime
,
int
type
,
Integer
width
,
Integer
height
,
Integer
bitrate
)
{
super
(
server
,
display
,
size
,
mime
,
type
);
this
.
width
=
width
;
this
.
height
=
height
;
this
.
bitrate
=
bitrate
;
}
public
Long
getWidth
()
{
public
Integer
getWidth
()
{
return
width
;
}
public
void
setWidth
(
Long
width
)
{
public
void
setWidth
(
Integer
width
)
{
this
.
width
=
width
;
}
public
Long
getHeight
()
{
public
Integer
getHeight
()
{
return
height
;
}
public
void
setHeight
(
Long
height
)
{
public
void
setHeight
(
Integer
height
)
{
this
.
height
=
height
;
}
public
Long
getBitrate
()
{
public
Integer
getBitrate
()
{
return
bitrate
;
}
public
void
setBitrate
(
Long
bitrate
)
{
public
void
setBitrate
(
Integer
bitrate
)
{
this
.
bitrate
=
bitrate
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/vo/YzgFileVideoImageItemReqVo.java
View file @
17f61a23
package
com
.
yanzuoguang
.
cloud
.
file
.
vo
;
import
com.yanzuoguang.util.vo.BaseVo
;
import
io.swagger.annotations.ApiModelProperty
;
import
javax.validation.constraints.NotNull
;
...
...
@@ -10,93 +9,29 @@ import javax.validation.constraints.NotNull;
*
* @author 颜佐光
*/
public
class
YzgFileVideoImageItemReqVo
extends
BaseVo
{
/**
* 高质量品质
*/
public
static
final
YzgFileVideoImageItemReqVo
VIDEO_TYPE_HIGH
=
new
YzgFileVideoImageItemReqVo
(
1
D
,
1
D
,
1920
,
1080
);
/**
* 常规品质
*/
public
static
final
YzgFileVideoImageItemReqVo
VIDEO_TYPE_COMMON
=
new
YzgFileVideoImageItemReqVo
(
1
D
,
1
D
,
800
,
600
);
/**
* 低质量品质
*/
public
static
final
YzgFileVideoImageItemReqVo
VIDEO_TYPE_LOW
=
new
YzgFileVideoImageItemReqVo
(
1
D
,
1
D
,
960
,
0
);
public
class
YzgFileVideoImageItemReqVo
extends
YzgFileConvertBase
{
@ApiModelProperty
(
notes
=
"目标文件"
)
private
String
toFile
;
@ApiModelProperty
(
notes
=
"压缩尺寸比例,默认为1,范围在0~1之间."
)
private
double
size
=
1
D
;
@ApiModelProperty
(
notes
=
"质量压缩比例,默认为1,范围在0~1之间."
)
private
double
quote
=
1
D
;
@ApiModelProperty
(
notes
=
"分辨率x,如: 1920*1080中的1920."
)
private
long
width
=
0
;
@ApiModelProperty
(
notes
=
"分辨率x,如: 1920*1080中的1080."
)
private
long
height
=
0
;
private
String
to
;
public
YzgFileVideoImageItemReqVo
()
{
}
private
YzgFileVideoImageItemReqVo
(
double
size
,
double
quote
,
long
width
,
long
height
)
{
this
.
size
=
size
;
this
.
quote
=
quote
;
this
.
width
=
width
;
this
.
height
=
height
;
}
public
YzgFileVideoImageItemReqVo
(
String
toFile
,
@NotNull
YzgFileVideoImageItemReqVo
from
)
{
this
(
from
.
size
,
from
.
quote
,
from
.
width
,
from
.
height
);
this
.
toFile
=
toFile
;
}
public
YzgFileVideoImageItemReqVo
(
String
toFile
,
double
size
,
double
quote
,
long
width
,
long
height
)
{
this
(
size
,
quote
,
width
,
height
);
this
.
toFile
=
toFile
;
}
public
String
getToFile
()
{
return
toFile
;
}
public
void
setToFile
(
String
toFile
)
{
this
.
toFile
=
toFile
;
}
public
double
getSize
()
{
return
size
;
}
public
void
setSize
(
double
size
)
{
this
.
size
=
size
;
}
public
double
getQuote
()
{
return
quote
;
}
public
void
setQuote
(
double
quote
)
{
this
.
quote
=
quote
;
}
public
long
getWidth
()
{
return
width
;
public
YzgFileVideoImageItemReqVo
(
String
to
,
@NotNull
YzgFileConvertBase
from
)
{
super
(
from
.
size
,
from
.
quote
,
from
.
width
,
from
.
height
,
from
.
bitrate
);
this
.
to
=
to
;
}
public
void
setWidth
(
long
width
)
{
this
.
width
=
width
;
public
YzgFileVideoImageItemReqVo
(
String
to
,
float
size
,
float
quote
,
int
width
,
int
height
,
int
bitrate
)
{
super
(
size
,
quote
,
width
,
height
,
bitrate
);
this
.
to
=
to
;
}
public
long
getHeight
()
{
return
height
;
public
String
getTo
()
{
return
to
;
}
public
void
set
Height
(
long
height
)
{
this
.
height
=
height
;
public
void
set
To
(
String
to
)
{
this
.
to
=
to
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/vo/YzgFileVideoImageReqVo.java
View file @
17f61a23
...
...
@@ -17,36 +17,36 @@ public class YzgFileVideoImageReqVo extends YzgFileMoveItemReqVo {
* 压缩后的文件参数集合
*/
@ApiModelProperty
(
notes
=
"压缩后的文件参数集合"
,
position
=
10000
)
private
List
<
YzgFileVideoImageReqVo
>
list
=
new
ArrayList
<>();
private
List
<
YzgFileVideoImage
Item
ReqVo
>
list
=
new
ArrayList
<>();
public
YzgFileVideoImageReqVo
()
{
}
public
YzgFileVideoImageReqVo
(
String
from
,
YzgFileVideoImageReqVo
...
list
)
{
public
YzgFileVideoImageReqVo
(
String
from
,
YzgFileVideoImage
Item
ReqVo
...
list
)
{
super
(
from
);
this
.
list
.
addAll
(
Arrays
.
asList
(
list
));
}
public
YzgFileVideoImageReqVo
(
String
from
,
String
to
,
YzgFileVideoImageReqVo
...
list
)
{
public
YzgFileVideoImageReqVo
(
String
from
,
String
to
,
YzgFileVideoImage
Item
ReqVo
...
list
)
{
super
(
from
,
to
);
this
.
list
.
addAll
(
Arrays
.
asList
(
list
));
}
public
YzgFileVideoImageReqVo
(
String
from
,
List
<
YzgFileVideoImageReqVo
>
list
)
{
public
YzgFileVideoImageReqVo
(
String
from
,
List
<
YzgFileVideoImage
Item
ReqVo
>
list
)
{
super
(
from
);
this
.
list
=
list
;
}
public
YzgFileVideoImageReqVo
(
String
from
,
String
to
,
List
<
YzgFileVideoImageReqVo
>
list
)
{
public
YzgFileVideoImageReqVo
(
String
from
,
String
to
,
List
<
YzgFileVideoImage
Item
ReqVo
>
list
)
{
super
(
from
,
to
);
this
.
list
=
list
;
}
public
List
<
YzgFileVideoImageReqVo
>
getList
()
{
public
List
<
YzgFileVideoImage
Item
ReqVo
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
YzgFileVideoImageReqVo
>
list
)
{
public
void
setList
(
List
<
YzgFileVideoImage
Item
ReqVo
>
list
)
{
this
.
list
=
list
;
}
}
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
17f61a23
...
...
@@ -8,7 +8,6 @@ import com.yanzuoguang.util.exception.CodeException;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.bytedeco.javacv.FFmpegFrameGrabber
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -22,6 +21,7 @@ import java.nio.file.Files;
import
java.nio.file.Paths
;
import
java.nio.file.StandardCopyOption
;
import
java.util.Date
;
import
java.util.List
;
/**
* 文件上传服务实现
...
...
@@ -126,6 +126,7 @@ public class YzgFileServiceImpl implements YzgFileService {
if
(
req
.
getList
()
==
null
||
req
.
getList
().
isEmpty
())
{
throw
new
CodeException
(
"请传入需要移动的文件"
);
}
// 先检查一遍参数
for
(
YzgFileMoveItemReqVo
item
:
req
.
getList
())
{
if
(
StringHelper
.
isEmpty
(
item
.
getFrom
()))
{
...
...
@@ -176,7 +177,6 @@ public class YzgFileServiceImpl implements YzgFileService {
throw
new
CodeException
(
String
.
format
(
"移动文件 %s 到 %s 失败,原因:%s"
,
item
.
getFrom
(),
item
.
getTo
(),
ex
.
getMessage
()));
}
}
}
/**
...
...
@@ -195,20 +195,20 @@ public class YzgFileServiceImpl implements YzgFileService {
switch
(
info
.
getType
())
{
case
FileHelper
.
FILE_TYPE_AUDIO
:
{
MediaParameter
parameter
=
MediaHelper
.
getGrabberParameter
(
serverFullPath
);
info
.
setBitrate
(
Long
.
valueOf
(
parameter
.
getAudioBitRate
()
));
info
.
setBitrate
(
parameter
.
getAudioBitRate
(
));
break
;
}
case
FileHelper
.
FILE_TYPE_VIDEO
:
{
MediaParameter
parameter
=
MediaHelper
.
getGrabberParameter
(
serverFullPath
);
info
.
setBitrate
(
Long
.
valueOf
(
parameter
.
getVideoBitRate
()
));
info
.
setWidth
(
Long
.
valueOf
(
parameter
.
getVideoWidth
()
));
info
.
setHeight
(
Long
.
valueOf
(
parameter
.
getVideoHeight
()
));
info
.
setBitrate
(
parameter
.
getVideoBitRate
(
));
info
.
setWidth
(
parameter
.
getVideoWidth
(
));
info
.
setHeight
(
parameter
.
getVideoHeight
(
));
break
;
}
case
FileHelper
.
FILE_TYPE_IMAGE
:
{
BufferedImage
sourceImg
=
ImageIO
.
read
(
new
FileInputStream
(
serverFullPath
));
info
.
setWidth
(
Long
.
valueOf
(
sourceImg
.
getWidth
()
));
info
.
setHeight
(
Long
.
valueOf
(
sourceImg
.
getHeight
()
));
info
.
setWidth
(
sourceImg
.
getWidth
(
));
info
.
setHeight
(
sourceImg
.
getHeight
(
));
break
;
}
case
FileHelper
.
FILE_TYPE_NONE
:
...
...
@@ -238,7 +238,7 @@ public class YzgFileServiceImpl implements YzgFileService {
* @param req
*/
@Override
public
void
convertVideoFirst
(
YzgFile
MoveItem
ReqVo
req
)
{
public
void
convertVideoFirst
(
YzgFile
ConvertVideoFirst
ReqVo
req
)
{
}
...
...
@@ -249,7 +249,54 @@ public class YzgFileServiceImpl implements YzgFileService {
*/
@Override
public
void
convertVideo
(
YzgFileVideoImageReqVo
req
)
{
List
<
YzgFileVideoImageItemReqVo
>
toFiles
=
req
.
getList
();
if
(
toFiles
==
null
||
toFiles
.
isEmpty
())
{
return
;
}
// 先循环检测参数
checkFolder
(
req
.
getFrom
());
for
(
YzgFileVideoImageItemReqVo
item
:
req
.
getList
())
{
checkFolder
(
item
.
getTo
());
}
// 来源文件路径
String
from
=
fileConfig
.
getServerFullPath
(
req
.
getFrom
());
for
(
YzgFileVideoImageItemReqVo
item
:
req
.
getList
())
{
String
to
=
fileConfig
.
getServerFullPath
(
item
.
getTo
());
// 先压缩到临时文件
String
toFileTemp
=
to
+
StringHelper
.
getNewID
()
+
".tmp"
;
MediaParameter
parameter
=
new
MediaParameter
(
item
.
getSize
(),
item
.
getQuote
());
// 设置最小宽度,指的是宽度和高度中的大值,宽度>高度
parameter
.
setMinVideoWidth
(
StringHelper
.
getFirst
(
item
.
getWidth
(),
parameter
.
getMinVideoWidth
()));
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
parameter
.
setMinVideoHeight
(
StringHelper
.
getFirst
(
item
.
getHeight
(),
parameter
.
getMinVideoHeight
()));
// 设置视频最小比特率
parameter
.
setMinVideoBitRate
(
StringHelper
.
getFirst
(
item
.
getBitrate
(),
parameter
.
getMinVideoBitRate
()));
// 将临时文件改成具体的文件
File
fileTemp
=
new
File
(
toFileTemp
);
File
file
=
new
File
(
to
);
try
{
if
(
fileTemp
.
exists
())
{
fileTemp
.
delete
();
}
// 压缩视频到临时文件
MediaHelper
.
zipVideoMp4
(
from
,
toFileTemp
,
parameter
);
// 判断文件是否存在,不存在则更改临时文件名
if
(
file
.
exists
())
{
file
.
delete
();
}
// 判断文件是否存在,文件不存在则压缩,文件存在则不压缩
fileTemp
.
renameTo
(
file
);
}
catch
(
IOException
ex
)
{
throw
new
CodeException
(
ex
);
}
finally
{
// 删除临时文件
if
(
fileTemp
.
exists
())
{
fileTemp
.
delete
();
}
}
}
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment