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
725262b1
Commit
725262b1
authored
Jul 14, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
视频压缩
parent
0e2090d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
16 deletions
+59
-16
MediaParameter.java
...ge/src/main/java/com/yanzuoguang/util/MediaParameter.java
+35
-3
TestMediaHelper.java
yzg-util-image/src/test/java/helper/TestMediaHelper.java
+24
-13
No files found.
yzg-util-image/src/main/java/com/yanzuoguang/util/MediaParameter.java
View file @
725262b1
...
@@ -123,6 +123,35 @@ public class MediaParameter extends BaseVo {
...
@@ -123,6 +123,35 @@ public class MediaParameter extends BaseVo {
@ApiModelProperty
(
notes
=
"视频比特率压缩比,算法为: 最终比特率= Math.max(minAudioBitRate,audioBitRate * audioBitRateZip)"
)
@ApiModelProperty
(
notes
=
"视频比特率压缩比,算法为: 最终比特率= Math.max(minAudioBitRate,audioBitRate * audioBitRateZip)"
)
private
float
videoBitRateZip
=
0
;
private
float
videoBitRateZip
=
0
;
/**
* 默认构造函数
*/
public
MediaParameter
()
{
}
/**
* 视频压缩
*
* @param videoSizeZip 宽,高,压缩比
* @param videoBitRateZip 比特率压缩比,相当于视频质量
*/
public
MediaParameter
(
float
videoSizeZip
,
float
videoBitRateZip
)
{
this
.
videoSizeZip
=
videoSizeZip
;
this
.
videoBitRateZip
=
videoBitRateZip
;
}
/**
* 视频压缩
*
* @param audioBitRateZip 音频质量压缩比
* @param videoSizeZip 宽,高,压缩比
* @param videoBitRateZip 比特率压缩比,相当于视频质量
*/
public
MediaParameter
(
float
audioBitRateZip
,
float
videoSizeZip
,
float
videoBitRateZip
)
{
this
.
audioBitRateZip
=
audioBitRateZip
;
this
.
videoSizeZip
=
videoSizeZip
;
this
.
videoBitRateZip
=
videoBitRateZip
;
}
/**
/**
* 音频最终比特率
* 音频最终比特率
...
@@ -317,6 +346,7 @@ public class MediaParameter extends BaseVo {
...
@@ -317,6 +346,7 @@ public class MediaParameter extends BaseVo {
this
.
videoBitRateZip
=
StringHelper
.
getFirst
(
this
.
videoBitRateZip
,
0.1f
);
this
.
videoBitRateZip
=
StringHelper
.
getFirst
(
this
.
videoBitRateZip
,
0.1f
);
// 设置压缩大小
// 设置压缩大小
this
.
videoSizeZip
=
StringHelper
.
getFirst
(
this
.
videoSizeZip
,
0.1f
);
this
.
videoSizeZip
=
StringHelper
.
getFirst
(
this
.
videoSizeZip
,
0.1f
);
// 设置音频最小比特率
// 设置音频最小比特率
this
.
minAudioBitRate
=
StringHelper
.
getFirst
(
this
.
minAudioBitRate
,
48043
);
this
.
minAudioBitRate
=
StringHelper
.
getFirst
(
this
.
minAudioBitRate
,
48043
);
}
}
...
@@ -330,7 +360,7 @@ public class MediaParameter extends BaseVo {
...
@@ -330,7 +360,7 @@ public class MediaParameter extends BaseVo {
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
360
);
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
360
);
// 设置视频最小比特率
// 设置视频最小比特率
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Audi
oBitRate
,
295581
);
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Vide
oBitRate
,
295581
);
}
}
/**
/**
...
@@ -341,6 +371,8 @@ public class MediaParameter extends BaseVo {
...
@@ -341,6 +371,8 @@ public class MediaParameter extends BaseVo {
this
.
minVideoWidth
=
StringHelper
.
getFirst
(
this
.
minVideoWidth
,
800
);
this
.
minVideoWidth
=
StringHelper
.
getFirst
(
this
.
minVideoWidth
,
800
);
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
600
);
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
600
);
// 设置视频最小比特率
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
minVideoBitRate
,
600000
);
}
}
/**
/**
...
@@ -350,7 +382,7 @@ public class MediaParameter extends BaseVo {
...
@@ -350,7 +382,7 @@ public class MediaParameter extends BaseVo {
// 设置最小宽度,指的是宽度和高度中的大值,宽度>高度
// 设置最小宽度,指的是宽度和高度中的大值,宽度>高度
this
.
minVideoWidth
=
StringHelper
.
getFirst
(
this
.
minVideoWidth
,
960
);
this
.
minVideoWidth
=
StringHelper
.
getFirst
(
this
.
minVideoWidth
,
960
);
// 设置视频最小比特率
// 设置视频最小比特率
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Audi
oBitRate
,
2955811
);
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Vide
oBitRate
,
2955811
);
}
}
/**
/**
...
@@ -362,7 +394,7 @@ public class MediaParameter extends BaseVo {
...
@@ -362,7 +394,7 @@ public class MediaParameter extends BaseVo {
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
// 设置最小高度,指的是宽度和高度中的小值,宽度>高度
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
1080
);
this
.
minVideoHeight
=
StringHelper
.
getFirst
(
this
.
minVideoHeight
,
1080
);
// 设置视频最小比特率
// 设置视频最小比特率
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Audi
oBitRate
,
8311136
);
this
.
minVideoBitRate
=
StringHelper
.
getFirst
(
this
.
min
Vide
oBitRate
,
8311136
);
}
}
/**
/**
...
...
yzg-util-image/src/test/java/helper/TestMediaHelper.java
View file @
725262b1
...
@@ -36,7 +36,7 @@ public class TestMediaHelper {
...
@@ -36,7 +36,7 @@ public class TestMediaHelper {
public
void
testConvert
()
throws
IOException
{
public
void
testConvert
()
throws
IOException
{
for
(
String
fileName
:
fileNames
)
{
for
(
String
fileName
:
fileNames
)
{
for
(
int
i
=
0
;
i
<
sizes
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
sizes
.
length
;
i
++)
{
testConvert
(
fileName
,
sizes
[
i
],
quotes
[
i
]
);
testConvert
(
fileName
,
new
MediaParameter
(
sizes
[
i
],
quotes
[
i
])
);
}
}
}
}
}
}
...
@@ -45,7 +45,7 @@ public class TestMediaHelper {
...
@@ -45,7 +45,7 @@ public class TestMediaHelper {
public
void
testConvertSingle
()
throws
IOException
{
public
void
testConvertSingle
()
throws
IOException
{
String
fileName
=
"100M.mp4"
;
String
fileName
=
"100M.mp4"
;
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
testConvert
(
fileName
,
0.25f
,
0.10f
);
testConvert
(
fileName
,
new
MediaParameter
(
0.25f
,
0.10f
)
);
}
}
...
@@ -53,27 +53,38 @@ public class TestMediaHelper {
...
@@ -53,27 +53,38 @@ public class TestMediaHelper {
public
void
testMinZipSingle
()
throws
IOException
{
public
void
testMinZipSingle
()
throws
IOException
{
String
fileName
=
"100M.mp4"
;
String
fileName
=
"100M.mp4"
;
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
testConvert
(
fileName
,
0.01f
,
0.01f
);
testConvert
(
fileName
,
new
MediaParameter
(
0.01f
,
0.01f
));
}
/**
* 按照微信的压缩标准
*
* @throws IOException
*/
@Test
public
void
testMinZipWeixin
()
throws
IOException
{
String
fileName
=
"100M.mp4"
;
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
MediaParameter
parameter
=
new
MediaParameter
(
0.01f
,
0.01f
);
parameter
.
initZip1920_1080
();
testConvert
(
fileName
,
parameter
);
}
}
@Test
@Test
public
void
testConvertSingle_Two
()
throws
IOException
{
public
void
testConvertSingle_Two
()
throws
IOException
{
String
fileName
=
"100M.mp4.size_50.quot_50.mp4"
;
String
fileName
=
"100M.mp4.size_50.quot_50.mp4"
;
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
// String fileName = "z001594372388232a3017ad69c82a342.MOV";
testConvert
(
fileName
,
0.5f
,
0.5f
);
testConvert
(
fileName
,
new
MediaParameter
(
0.5f
,
0.5f
)
);
}
}
private
void
testConvert
(
String
fileName
,
float
size
,
float
quote
)
throws
IOException
{
private
void
testConvert
(
String
fileName
,
MediaParameter
parameter
)
throws
IOException
{
if
(
parameter
==
null
)
{
parameter
=
new
MediaParameter
();
}
String
file
=
getFile
(
fileName
);
String
file
=
getFile
(
fileName
);
String
targetFile
=
getTargetFile
(
"target/"
+
fileName
);
String
targetFile
=
getTargetFile
(
"target/"
+
fileName
);
String
toFile
=
String
.
format
(
"%s.size_%d.quot_%d.mp4"
,
targetFile
,
(
int
)
(
parameter
.
getVideoSizeZip
()
*
100
),
(
int
)
(
parameter
.
getVideoBitRateZip
()
*
100
));
String
toFile
=
String
.
format
(
"%s.size_%d.quot_%d.mp4"
,
targetFile
,
(
int
)
(
size
*
100
),
(
int
)
(
quote
*
100
));
MediaParameter
parameter
=
new
MediaParameter
();
parameter
.
setVideoSizeZip
(
size
);
parameter
.
setVideoBitRateZip
(
quote
);
MediaHelper
.
zipVideoMp4
(
file
,
toFile
,
parameter
);
MediaHelper
.
zipVideoMp4
(
file
,
toFile
,
parameter
);
}
}
}
}
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