|
@@ -1,19 +1,17 @@
|
|
|
package cn.reghao.dfs.store.task;
|
|
package cn.reghao.dfs.store.task;
|
|
|
|
|
|
|
|
import cn.reghao.dfs.store.db.repository.MediaRepository;
|
|
import cn.reghao.dfs.store.db.repository.MediaRepository;
|
|
|
-import cn.reghao.dfs.store.model.po.VideoUrl;
|
|
|
|
|
|
|
+import cn.reghao.dfs.store.model.po.AudioFile;
|
|
|
import cn.reghao.dfs.store.model.vo.ObjectProp;
|
|
import cn.reghao.dfs.store.model.vo.ObjectProp;
|
|
|
import cn.reghao.dfs.store.model.vo.ObjectResult;
|
|
import cn.reghao.dfs.store.model.vo.ObjectResult;
|
|
|
import cn.reghao.dfs.store.service.FileStoreService;
|
|
import cn.reghao.dfs.store.service.FileStoreService;
|
|
|
import cn.reghao.dfs.store.service.ObjectNameService;
|
|
import cn.reghao.dfs.store.service.ObjectNameService;
|
|
|
import cn.reghao.dfs.store.service.PutObjectService;
|
|
import cn.reghao.dfs.store.service.PutObjectService;
|
|
|
-import cn.reghao.dfs.store.util.FileType;
|
|
|
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
import cn.reghao.jutil.media.FFmpegWrapper;
|
|
import cn.reghao.jutil.media.FFmpegWrapper;
|
|
|
import cn.reghao.jutil.media.model.AudioProps;
|
|
import cn.reghao.jutil.media.model.AudioProps;
|
|
|
import cn.reghao.jutil.media.model.MediaProps;
|
|
import cn.reghao.jutil.media.model.MediaProps;
|
|
|
-import cn.reghao.oss.api.constant.UploadChannel;
|
|
|
|
|
import cn.reghao.oss.api.rest.UploadFileRet;
|
|
import cn.reghao.oss.api.rest.UploadFileRet;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -47,63 +45,70 @@ public class AudioFileProcessor {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public UploadFileRet process(ObjectResult objectResult) {
|
|
public UploadFileRet process(ObjectResult objectResult) {
|
|
|
- String objectId = objectResult.getObjectId();
|
|
|
|
|
|
|
+ String originalObjectName = objectResult.getObjectName();
|
|
|
|
|
+ String originalObjectId = objectResult.getObjectId();
|
|
|
boolean duplicate = objectResult.isDuplicate();
|
|
boolean duplicate = objectResult.isDuplicate();
|
|
|
if (duplicate) {
|
|
if (duplicate) {
|
|
|
|
|
+ ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".m4a");
|
|
|
|
|
+ String objectId1 = objectResult1.getObjectId();
|
|
|
|
|
+ String url1 = objectNameService.getObjectUrl(objectResult1.getObjectName());
|
|
|
|
|
+
|
|
|
String dupObjectId = objectResult.getDupObjectId();
|
|
String dupObjectId = objectResult.getDupObjectId();
|
|
|
- return null;
|
|
|
|
|
|
|
+ AudioFile audioFile = mediaRepository.findAudioFile(dupObjectId);
|
|
|
|
|
+ String audioCodec = audioFile.getCodec();
|
|
|
|
|
+ AudioFile audioFile1 = new AudioFile(originalObjectId, objectId1, audioCodec, url1);
|
|
|
|
|
+ mediaRepository.saveAudioFile(audioFile1);
|
|
|
|
|
+ return new UploadFileRet(objectId1, url1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String objectName = objectResult.getObjectName();
|
|
|
|
|
String absolutePath = objectResult.getAbsolutePath();
|
|
String absolutePath = objectResult.getAbsolutePath();
|
|
|
MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
MediaProps mediaProps = FFmpegWrapper.getMediaProps(absolutePath);
|
|
|
- if (mediaProps == null) {
|
|
|
|
|
- log.info("{} 的 FFmpeg 媒体信息为 null", objectName);
|
|
|
|
|
|
|
+ if (mediaProps == null || mediaProps.getAudioProps() == null) {
|
|
|
|
|
+ log.error("{} 的 FFmpeg 音频信息为 null", originalObjectName);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AudioProps audioProps = mediaProps.getAudioProps();
|
|
AudioProps audioProps = mediaProps.getAudioProps();
|
|
|
- if (audioProps == null) {
|
|
|
|
|
- log.info("{} 的 FFmpeg 音频信息为 null", objectName);
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
String audioCodec = audioProps.getCodecName();
|
|
String audioCodec = audioProps.getCodecName();
|
|
|
if (!audioCodecs.contains(audioCodec)) {
|
|
if (!audioCodecs.contains(audioCodec)) {
|
|
|
- log.error("{} 对象的音频非 aac 编码, 暂不处理", objectName);
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ log.info("将 {} 对象的音频转换为 aac 编码", originalObjectName);
|
|
|
|
|
+ File file = new File(objectResult.getAbsolutePath());
|
|
|
|
|
+ UploadFileRet uploadFileRet = getConvertedAudioFile(originalObjectId, file, originalObjectName, ".m4a");
|
|
|
|
|
+ return uploadFileRet;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //log.info("添加视频格式转码任务");
|
|
|
|
|
- //threadPool.submit(new ConvertTask());
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ ObjectResult objectResult1 = putObjectService.copyObject(originalObjectName, ".m4a");
|
|
|
|
|
+ String objectId1 = objectResult1.getObjectId();
|
|
|
|
|
+ String url1 = objectNameService.getObjectUrl(objectResult1.getObjectName());
|
|
|
|
|
+ AudioFile audioFile = new AudioFile(originalObjectId, objectId1, audioCodec, url1);
|
|
|
|
|
+ mediaRepository.saveAudioFile(audioFile);
|
|
|
|
|
+ return new UploadFileRet(objectId1, url1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private VideoUrl getConvertedAudioUrl(String audioFileId, File file) {
|
|
|
|
|
|
|
+ private UploadFileRet getConvertedAudioFile(String audioFileId, File file, String originalObjectName, String suffix) {
|
|
|
String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
|
- fileStoreService.genFilePath(contentId, file.length());
|
|
|
|
|
- String absolutePath = fileStoreService.genFilePath(contentId, file.length());
|
|
|
|
|
|
|
+ String destPath = fileStoreService.genFilePath(contentId, file.length(), suffix);
|
|
|
try {
|
|
try {
|
|
|
- File savedFile = new File(absolutePath);
|
|
|
|
|
|
|
+ File savedFile = new File(destPath);
|
|
|
if (savedFile.exists()) {
|
|
if (savedFile.exists()) {
|
|
|
- throw new IOException(absolutePath + " exist");
|
|
|
|
|
|
|
+ throw new IOException(destPath + " exist");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String suffix = "m4a";
|
|
|
|
|
- int ret = FFmpegWrapper.convertAudio(file.getAbsolutePath(), absolutePath + "." + suffix);
|
|
|
|
|
|
|
+ int ret = FFmpegWrapper.convertAudio(file.getAbsolutePath(), destPath);
|
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
|
throw new Exception("音频转码失败");
|
|
throw new Exception("音频转码失败");
|
|
|
}
|
|
}
|
|
|
- String sha256sum = DigestUtil.sha256sum(absolutePath);
|
|
|
|
|
|
|
+ String sha256sum = DigestUtil.sha256sum(destPath);
|
|
|
|
|
|
|
|
- ObjectProp objectProp = objectNameService.getObjectProp(UploadChannel.audio.getCode());
|
|
|
|
|
|
|
+ ObjectProp objectProp = objectNameService.getObjectProp(originalObjectName, suffix);
|
|
|
String originalFilename = "";
|
|
String originalFilename = "";
|
|
|
ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, originalFilename, sha256sum);
|
|
ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, originalFilename, sha256sum);
|
|
|
-
|
|
|
|
|
String objectId = objectResult.getObjectId();
|
|
String objectId = objectResult.getObjectId();
|
|
|
String url = objectNameService.getObjectUrl(objectResult.getObjectName());
|
|
String url = objectNameService.getObjectUrl(objectResult.getObjectName());
|
|
|
- String urlType = FileType.getVideoUrlType(absolutePath);
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ String codec = "aac";
|
|
|
|
|
+ AudioFile audioFile = new AudioFile(audioFileId, objectId, codec, url);
|
|
|
|
|
+ mediaRepository.saveAudioFile(audioFile);
|
|
|
|
|
+ return new UploadFileRet(objectId, url);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|