Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
liyaoting
/
update-video
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 44d9b2be
authored
2023-04-26 23:24:29 +0800
by
liyaoting
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
下载
oss没提供从链接获取视频封面的视频的封面 的功能
1 parent
11c7072c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
6 deletions
pom.xml
src/main/java/cn/bxe/updatevideo/UpdateVideoApplication.java
pom.xml
View file @
44d9b2b
...
@@ -23,6 +23,11 @@
...
@@ -23,6 +23,11 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
com.mysql
</groupId>
<groupId>
com.mysql
</groupId>
<artifactId>
mysql-connector-j
</artifactId>
<artifactId>
mysql-connector-j
</artifactId>
<version>
8.0.31
</version>
<version>
8.0.31
</version>
...
@@ -75,6 +80,17 @@
...
@@ -75,6 +80,17 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.bytedeco
</groupId>
<artifactId>
javacv
</artifactId>
<version>
1.5.6
</version>
</dependency>
<dependency>
<groupId>
org.bytedeco
</groupId>
<artifactId>
ffmpeg-platform
</artifactId>
<version>
4.4-1.5.6
</version>
</dependency>
<dependency>
<groupId>
ws.schild
</groupId>
<groupId>
ws.schild
</groupId>
<artifactId>
jave-core
</artifactId>
<artifactId>
jave-core
</artifactId>
<version>
2.4.6
</version>
<version>
2.4.6
</version>
...
...
src/main/java/cn/bxe/updatevideo/UpdateVideoApplication.java
View file @
44d9b2b
...
@@ -20,6 +20,9 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -20,6 +20,9 @@ import com.alibaba.fastjson.JSONObject;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
org.bytedeco.javacv.FFmpegFrameGrabber
;
import
org.bytedeco.javacv.Frame
;
import
org.bytedeco.javacv.Java2DFrameConverter
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -30,7 +33,12 @@ import org.springframework.util.CollectionUtils;
...
@@ -30,7 +33,12 @@ import org.springframework.util.CollectionUtils;
import
ws.schild.jave.FfmpegFileInfo
;
import
ws.schild.jave.FfmpegFileInfo
;
import
ws.schild.jave.MultimediaInfo
;
import
ws.schild.jave.MultimediaInfo
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -53,12 +61,12 @@ public class UpdateVideoApplication {
...
@@ -53,12 +61,12 @@ public class UpdateVideoApplication {
.
addMsgConvertor
(
new
GsonMsgConvertor
())
.
addMsgConvertor
(
new
GsonMsgConvertor
())
.
build
();
.
build
();
private
static
final
ThreadPoolExecutor
pool
=
new
ThreadPoolExecutor
(
20
,
2
0
,
private
static
final
ThreadPoolExecutor
pool
=
new
ThreadPoolExecutor
(
10
,
1
0
,
0
,
TimeUnit
.
SECONDS
,
0
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
30
),
new
ArrayBlockingQueue
<>(
30
),
new
ThreadPoolExecutor
.
DiscardPolicy
());
new
ThreadPoolExecutor
.
DiscardPolicy
());
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
,
IOException
{
ConfigurableApplicationContext
ctx
=
SpringApplication
.
run
(
UpdateVideoApplication
.
class
,
args
);
ConfigurableApplicationContext
ctx
=
SpringApplication
.
run
(
UpdateVideoApplication
.
class
,
args
);
bookService
=
ctx
.
getBean
(
TbxXrBookServiceImpl
.
class
);
bookService
=
ctx
.
getBean
(
TbxXrBookServiceImpl
.
class
);
chapterService
=
ctx
.
getBean
(
TbxXrChapterServiceImpl
.
class
);
chapterService
=
ctx
.
getBean
(
TbxXrChapterServiceImpl
.
class
);
...
@@ -69,7 +77,7 @@ public class UpdateVideoApplication {
...
@@ -69,7 +77,7 @@ public class UpdateVideoApplication {
Thread
.
currentThread
().
join
();
Thread
.
currentThread
().
join
();
}
}
private
static
void
menu
()
throws
InterruptedException
{
private
static
void
menu
()
throws
InterruptedException
,
IOException
{
System
.
out
.
println
(
"=========菜单========="
);
System
.
out
.
println
(
"=========菜单========="
);
System
.
out
.
println
(
"1: 更新书籍"
);
System
.
out
.
println
(
"1: 更新书籍"
);
System
.
out
.
println
(
"2: 更新章节"
);
System
.
out
.
println
(
"2: 更新章节"
);
...
@@ -79,6 +87,7 @@ public class UpdateVideoApplication {
...
@@ -79,6 +87,7 @@ public class UpdateVideoApplication {
System
.
out
.
println
(
"6: 更新数据库视频封面链接"
);
System
.
out
.
println
(
"6: 更新数据库视频封面链接"
);
System
.
out
.
println
(
"7: 补充视频时长"
);
System
.
out
.
println
(
"7: 补充视频时长"
);
System
.
out
.
println
(
"8: 计算数量"
);
System
.
out
.
println
(
"8: 计算数量"
);
System
.
out
.
println
(
"9: 下载oss5rsme视频封面"
);
System
.
out
.
println
(
"0: 退出"
);
System
.
out
.
println
(
"0: 退出"
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"请输入功能代码: "
);
System
.
out
.
print
(
"请输入功能代码: "
);
...
@@ -117,6 +126,10 @@ public class UpdateVideoApplication {
...
@@ -117,6 +126,10 @@ public class UpdateVideoApplication {
System
.
out
.
println
(
"计算"
);
System
.
out
.
println
(
"计算"
);
countSubjectVideo
();
countSubjectVideo
();
break
;
break
;
case
"9"
:
System
.
out
.
println
(
"下载oss5rsme视频封面"
);
getOss5rsmeCover
();
break
;
case
"0"
:
case
"0"
:
System
.
out
.
println
(
"退出咯"
);
System
.
out
.
println
(
"退出咯"
);
System
.
exit
(
0
);
System
.
exit
(
0
);
...
@@ -350,7 +363,7 @@ public class UpdateVideoApplication {
...
@@ -350,7 +363,7 @@ public class UpdateVideoApplication {
moduleService
.
saveBatch
(
tbxXrModuleList
);
moduleService
.
saveBatch
(
tbxXrModuleList
);
logger
.
info
(
"书籍{}/{},开始处理章节: {}/{},更新模块数:{}"
,
currentBookNum
,
bookNum
,
currentChapterNum
,
chapterNum
,
tbxXrModuleList
.
size
());
logger
.
info
(
"书籍{}/{},开始处理章节: {}/{},更新模块数:{}"
,
currentBookNum
,
bookNum
,
currentChapterNum
,
chapterNum
,
tbxXrModuleList
.
size
());
}
else
{
}
else
{
logger
.
info
(
"章节: {}/{},无
更新
"
,
currentChapterNum
,
chapterNum
);
logger
.
info
(
"章节: {}/{},无"
,
currentChapterNum
,
chapterNum
);
}
}
}
else
{
}
else
{
logger
.
info
(
"章节: {}/{},无内容~"
,
currentChapterNum
,
chapterNum
);
logger
.
info
(
"章节: {}/{},无内容~"
,
currentChapterNum
,
chapterNum
);
...
@@ -524,7 +537,7 @@ public class UpdateVideoApplication {
...
@@ -524,7 +537,7 @@ public class UpdateVideoApplication {
File
file
=
new
File
(
filePath
);
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
//如果文件小于50kb,可能是下载失败的文件,重新下载
//如果文件小于50kb,可能是下载失败的文件,重新下载
if
(
file
.
length
()
/
1024
<
5
0
)
{
if
(
file
.
length
()
/
1024
<
2
0
)
{
boolean
delete
=
file
.
delete
();
boolean
delete
=
file
.
delete
();
System
.
out
.
println
(
"删除未成功下载的文件"
);
System
.
out
.
println
(
"删除未成功下载的文件"
);
}
else
{
}
else
{
...
@@ -630,7 +643,7 @@ public class UpdateVideoApplication {
...
@@ -630,7 +643,7 @@ public class UpdateVideoApplication {
List
<
TbxXrBook
>
list
=
bookService
.
list
(
qw
);
List
<
TbxXrBook
>
list
=
bookService
.
list
(
qw
);
List
<
Integer
>
collect
=
list
.
stream
().
map
(
TbxXrBook:
:
getTextbookId
).
collect
(
Collectors
.
toList
());
List
<
Integer
>
collect
=
list
.
stream
().
map
(
TbxXrBook:
:
getTextbookId
).
collect
(
Collectors
.
toList
());
LambdaQueryWrapper
<
TbxXrModule
>
moduleQW
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
TbxXrModule
>
moduleQW
=
new
LambdaQueryWrapper
<>();
if
(
collect
.
size
()
>
0
){
if
(
collect
.
size
()
>
0
)
{
moduleQW
.
in
(
TbxXrModule:
:
getTextbookId
,
collect
);
moduleQW
.
in
(
TbxXrModule:
:
getTextbookId
,
collect
);
List
<
TbxXrModule
>
list1
=
moduleService
.
list
(
moduleQW
);
List
<
TbxXrModule
>
list1
=
moduleService
.
list
(
moduleQW
);
...
@@ -644,6 +657,47 @@ public class UpdateVideoApplication {
...
@@ -644,6 +657,47 @@ public class UpdateVideoApplication {
});
});
}
}
/**
* 获取oss.5rs.me的视频封面
*
* @throws IOException
* @throws InterruptedException
*/
private
static
void
getOss5rsmeCover
()
throws
IOException
,
InterruptedException
{
LambdaQueryWrapper
<
TbxXrVideo
>
qw
=
new
LambdaQueryWrapper
<>();
qw
.
like
(
TbxXrVideo:
:
getUrl
,
"https://oss.5rs.me"
);
List
<
TbxXrVideo
>
list
=
videoService
.
list
(
qw
);
for
(
TbxXrVideo
tbxXrVideo
:
list
)
{
//如果已存在则跳过
String
imgName
=
"xrv_"
+
tbxXrVideo
.
getVideoId
()
+
".jpg"
;
String
filePath
=
"D:\\ossvideo\\"
+
imgName
;
File
picFile
=
new
File
(
filePath
);
boolean
exists
=
picFile
.
exists
();
if
(
exists
)
{
continue
;
}
FFmpegFrameGrabber
ff
=
new
FFmpegFrameGrabber
(
tbxXrVideo
.
getUrl
());
ff
.
start
();
Frame
frame
=
null
;
for
(
int
i
=
0
;
i
<
75
;
i
++)
{
//获取第三秒第一帧
frame
=
ff
.
grabImage
();
}
if
(
frame
.
image
==
null
)
{
continue
;
}
Java2DFrameConverter
converter
=
new
Java2DFrameConverter
();
//创建一个帧-->图片的转换器
BufferedImage
image
=
converter
.
getBufferedImage
(
frame
);
//转换
//将图片保存到目标文件中
ImageIO
.
write
(
image
,
"jpg"
,
picFile
);
ff
.
stop
();
ff
.
close
();
}
}
private
static
TbxXrModule
moduleConvert
(
Module
module
)
{
private
static
TbxXrModule
moduleConvert
(
Module
module
)
{
TbxXrModule
tbxXrModule
=
new
TbxXrModule
();
TbxXrModule
tbxXrModule
=
new
TbxXrModule
();
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment