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
6e170c8b
Commit
6e170c8b
authored
Jun 01, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
a57f74da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
3 deletions
+94
-3
MediaHelper.java
...image/src/main/java/com/yanzuoguang/util/MediaHelper.java
+7
-3
TestMediaHelper.java
yzg-util-image/src/test/java/helper/TestMediaHelper.java
+87
-0
ffmpeg
yzg-util-image/src/test/java/helper/ffmpeg
+0
-0
No files found.
yzg-util-image/src/main/java/com/yanzuoguang/util/MediaHelper.java
View file @
6e170c8b
...
...
@@ -36,8 +36,9 @@ public class MediaHelper {
public
static
final
String
FORMAT_EMPTY
=
""
;
public
static
final
String
FORMAT_FLV
=
"flv"
;
public
static
final
String
FORMAT_MPEG
=
"mp
egvideo
"
;
public
static
final
String
FORMAT_MPEG
=
"mp
4
"
;
public
static
final
String
FORMAT_MPEG_CODEC
=
"mpeg4"
;
// public static final String FORMAT_MPEG_CODEC = "mpeg";
public
static
final
String
FORMAT_3PG
=
"3gp"
;
public
static
final
String
FORMAT_3PG_CODEC
=
"mpeg4"
;
...
...
@@ -274,8 +275,9 @@ public class MediaHelper {
// 视频编码设置
VideoAttributes
video
=
new
VideoAttributes
();
// video.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
video
.
setCodec
(
codeC
);
int
fromFrameRate
=
(
int
)
(
fromVideo
.
getFrameRate
()
);
// video.setTag("DIVX"
);
int
toFrameRate
=
15
;
video
.
setFrameRate
(
toFrameRate
);
// 压缩比特率
...
...
@@ -283,7 +285,9 @@ public class MediaHelper {
// 压缩宽高
VideoSize
fromSize
=
fromVideo
.
getSize
();
VideoSize
toSize
=
new
VideoSize
((
int
)
(
fromSize
.
getWidth
()
*
size
),
(
int
)
(
fromSize
.
getHeight
()
*
size
));
int
toWidth
=
(
int
)
(
fromSize
.
getWidth
()
*
size
);
int
toHeight
=
(
int
)
(
fromSize
.
getHeight
()
*
size
);
VideoSize
toSize
=
new
VideoSize
(
toWidth
,
toHeight
);
video
.
setSize
(
toSize
);
Log
.
info
(
MediaHelper
.
class
,
"%s-%s "
+
...
...
yzg-util-image/src/test/java/helper/TestMediaHelper.java
View file @
6e170c8b
...
...
@@ -2,6 +2,7 @@ package helper;
import
com.yanzuoguang.util.MediaHelper
;
import
com.yanzuoguang.util.thread.RunnableListAuto
;
import
it.sauronsoftware.jave.Encoder
;
import
it.sauronsoftware.jave.EncoderException
;
import
org.junit.Test
;
...
...
@@ -16,6 +17,50 @@ public class TestMediaHelper {
public
float
[]
sizes
=
new
float
[]{
1
f
,
0.5f
,
1
f
,
1
f
,
0.5f
,
0.5f
};
public
float
[]
quotes
=
new
float
[]{
1
f
,
1
f
,
0.5f
,
0.25f
,
0.5f
,
0.25f
};
@Test
public
void
printEncoding
()
throws
EncoderException
{
Encoder
encoder
=
new
Encoder
();
String
[]
audioEncoders
=
encoder
.
getVideoEncoders
();
for
(
String
item
:
audioEncoders
)
{
System
.
out
.
println
(
item
);
}
}
@Test
public
void
testConvert
()
throws
EncoderException
{
Encoder
encoder
=
new
Encoder
();
String
[]
audioEncoders
=
encoder
.
getVideoEncoders
();
List
<
Runnable
>
list
=
new
ArrayList
<>();
for
(
String
item
:
audioEncoders
)
{
list
.
add
(
testConvertThread
(
item
,
1
f
,
1
f
));
}
RunnableListAuto
.
run
(
list
);
}
private
Runnable
testConvertThread
(
String
item
,
float
size
,
float
quote
)
{
return
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
testConvert
(
item
,
size
,
quote
);
}
catch
(
EncoderException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
};
}
private
void
testConvert
(
String
item
,
float
size
,
float
quote
)
throws
EncoderException
{
String
file
=
getFile
();
String
targetFile
=
getTargetFile
();
String
name
=
String
.
format
(
"%s.size_%d.quot_%d.%s.mp4"
,
targetFile
,
(
int
)
(
size
*
100
),
(
int
)
(
quote
*
100
),
item
);
MediaHelper
.
zipVideo
(
file
,
name
,
"mp4"
,
item
,
size
,
(
int
)
(
MediaHelper
.
DEFAULT_BIT_RATE
*
quote
));
}
private
String
getFile
()
{
// 注意,路径应为文件在工程中的相对路径
File
f
=
new
File
(
"src/test/java/helper/100M.mp4"
);
...
...
@@ -114,6 +159,11 @@ public class TestMediaHelper {
}
@Test
public
void
testVideoZipMpeg_50_50
()
throws
EncoderException
{
testVideoZipMpeg
(
0.5f
,
0.5f
);
}
@Test
public
void
testVideoZipMpeg
()
throws
EncoderException
{
List
<
Runnable
>
list
=
new
ArrayList
<>();
...
...
@@ -174,4 +224,41 @@ public class TestMediaHelper {
targetFile
,
(
int
)
(
size
*
100
),
(
int
)
(
quote
*
100
));
MediaHelper
.
zipVideo3pg
(
file
,
name
,
size
,
(
int
)
(
MediaHelper
.
DEFAULT_BIT_RATE
*
quote
));
}
@Test
public
void
testVideoZip_50_50
()
throws
EncoderException
{
testVideoZip
(
0.5f
,
0.5f
);
}
@Test
public
void
testVideoZip
()
throws
EncoderException
{
List
<
Runnable
>
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
sizes
.
length
;
i
++)
{
list
.
add
(
testVideoZipThread
(
sizes
[
i
],
quotes
[
i
]));
}
RunnableListAuto
.
run
(
list
);
}
private
Runnable
testVideoZipThread
(
float
size
,
float
quote
)
{
return
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
testVideoZip
(
size
,
quote
);
}
catch
(
EncoderException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
};
}
private
void
testVideoZip
(
float
size
,
float
quote
)
throws
EncoderException
{
String
file
=
getFile
();
String
targetFile
=
getTargetFile
();
String
name
=
String
.
format
(
"%s.size_%d.quot_%d.mp4"
,
targetFile
,
(
int
)
(
size
*
100
),
(
int
)
(
quote
*
100
));
MediaHelper
.
zipVideo
(
file
,
name
,
size
,
(
int
)
(
MediaHelper
.
DEFAULT_BIT_RATE
*
quote
));
}
}
yzg-util-image/src/test/java/helper/ffmpeg
0 → 100755
View file @
6e170c8b
File added
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