|
|
@@ -1,7 +1,7 @@
|
|
|
package cn.reghao.dfs.store.task;
|
|
|
|
|
|
-import cn.reghao.oss.api.dto.VideoInfo;
|
|
|
-import cn.reghao.oss.api.dto.VideoUrlDto;
|
|
|
+import cn.reghao.dfs.store.util.media.po.AudioProps;
|
|
|
+import cn.reghao.dfs.store.util.media.po.VideoProps;
|
|
|
import cn.reghao.oss.api.dto.VideoUrlType;
|
|
|
import cn.reghao.dfs.store.config.OssProperties;
|
|
|
import cn.reghao.dfs.store.db.mapper.VideoFileMapper;
|
|
|
@@ -13,9 +13,9 @@ import cn.reghao.dfs.store.util.media.MediaQuality;
|
|
|
import cn.reghao.dfs.store.util.media.MediaResolution;
|
|
|
import cn.reghao.dfs.store.util.media.po.MediaProps;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
@@ -23,6 +23,7 @@ import java.util.concurrent.ExecutorService;
|
|
|
* @author reghao
|
|
|
* @date 2023-01-11 10:40:17
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class VideoFileProcessor {
|
|
|
private final VideoFileMapper videoFileMapper;
|
|
|
@@ -36,39 +37,47 @@ public class VideoFileProcessor {
|
|
|
this.endpoint = ossProperties.getDomain();
|
|
|
}
|
|
|
|
|
|
- public void setVideoInfo(VideoInfo videoInfo) {
|
|
|
- String videoFileId = videoInfo.getVideoId();
|
|
|
- String videoObjectName = videoInfo.getVideoObjectName();
|
|
|
- int width = videoInfo.getWidth();
|
|
|
- int height = videoInfo.getHeight();
|
|
|
- String url = String.format("%s/%s", endpoint, videoObjectName);
|
|
|
+ public void process(String objectName, String objectId, String absolutePath) {
|
|
|
+ MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
|
+ if (mediaProps == null) {
|
|
|
+ log.info("{} 的 FFmpeg 媒体信息为 null", objectName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ VideoProps videoProps = mediaProps.getVideoProps();
|
|
|
+ if (videoProps == null) {
|
|
|
+ log.info("{} 的 FFmpeg 视频信息为 null", objectName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String videoFileId = objectId;
|
|
|
+ int width = videoProps.getCodedWidth().intValue();
|
|
|
+ int height = videoProps.getCodedHeight().intValue();
|
|
|
+ boolean horizontal = width>height;
|
|
|
+ int duration = videoProps.getDuration().intValue();
|
|
|
+ String url = String.format("%s/%s", endpoint, objectName);
|
|
|
|
|
|
- VideoFile videoFile = new VideoFile(videoInfo);
|
|
|
+ VideoFile videoFile = new VideoFile(videoFileId, objectName, horizontal, duration);
|
|
|
videoFileMapper.save(videoFile);
|
|
|
- try {
|
|
|
- String destPath = "/opt/tmp/tomcat/" + UUID.randomUUID().toString().replace("-", "");
|
|
|
- MediaProps mediaProps = FFmpegWrapper.getMediaProps(destPath);
|
|
|
- if (mediaProps != null && mediaProps.getAudioProps() != null && mediaProps.getVideoProps() != null) {
|
|
|
- String audioCodec = mediaProps.getAudioProps().getCodecName();
|
|
|
- String videoCodec = mediaProps.getVideoProps().getCodecName();
|
|
|
- if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) {
|
|
|
- MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
|
- VideoUrl videoUrl = new VideoUrl(videoFileId, videoObjectName, VideoUrlType.mp4.name(), url, mediaResolution);
|
|
|
- videoUrlMapper.save(videoUrl);
|
|
|
- } else {
|
|
|
- ConvertTask convertTask = new ConvertTask(videoFileId, destPath, endpoint, videoUrlMapper);
|
|
|
- threadPool.submit(convertTask);
|
|
|
- }
|
|
|
- } else {
|
|
|
- ConvertTask convertTask = new ConvertTask(videoFileId, destPath, endpoint, videoUrlMapper);
|
|
|
- threadPool.submit(convertTask);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+
|
|
|
+ AudioProps audioProps = mediaProps.getAudioProps();
|
|
|
+ if (audioProps == null) {
|
|
|
+ log.info("{} 的 FFmpeg 视频信息为 null", objectName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String audioCodec = mediaProps.getAudioProps().getCodecName();
|
|
|
+ String videoCodec = mediaProps.getVideoProps().getCodecName();
|
|
|
+ if ("aac".equals(audioCodec) && "h264".equals(videoCodec)) {
|
|
|
+ MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
|
|
|
+ VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, VideoUrlType.mp4.name(), url, mediaResolution);
|
|
|
+ videoUrlMapper.save(videoUrl);
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- public List<VideoUrlDto> getVideoUrls(String videoFileId, String urlType) {
|
|
|
- return videoUrlMapper.findVideoUrls(videoFileId, urlType);
|
|
|
+ String destPath = "/opt/tmp/tomcat/" + UUID.randomUUID().toString().replace("-", "");
|
|
|
+ ConvertTask convertTask = new ConvertTask(videoFileId, destPath, endpoint, videoUrlMapper);
|
|
|
+ log.info("添加视频格式转码任务");
|
|
|
+ //threadPool.submit(convertTask);
|
|
|
}
|
|
|
}
|