|
@@ -81,21 +81,23 @@ public class AudioFileProcessor {
|
|
|
String audioCodec = audioProps.getCodecName();
|
|
String audioCodec = audioProps.getCodecName();
|
|
|
int duration = audioProps.getDuration().intValue();
|
|
int duration = audioProps.getDuration().intValue();
|
|
|
long bitRate = audioProps.getBitRate();
|
|
long bitRate = audioProps.getBitRate();
|
|
|
- AudioFile audioFile;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ List<AudioFile> list = new ArrayList<>();
|
|
|
|
|
+ AudioFile audioFile = new AudioFile(audioFileId, objectId, duration, audioCodec, bitRate, objectUrl);
|
|
|
|
|
+ list.add(audioFile);
|
|
|
|
|
+
|
|
|
if (!SupportedMedia.audioCodecs.contains(audioCodec)) {
|
|
if (!SupportedMedia.audioCodecs.contains(audioCodec)) {
|
|
|
- log.info("将 {} 对象的音频转换为 aac 编码", objectName);
|
|
|
|
|
File file = new File(objectResult.getAbsolutePath());
|
|
File file = new File(objectResult.getAbsolutePath());
|
|
|
- audioFile = getConvertedAudioFile(audioFileId, file, objectName, ".m4a");
|
|
|
|
|
- } else {
|
|
|
|
|
- audioFile = new AudioFile(audioFileId, objectId, duration, audioCodec, bitRate, objectUrl);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (audioFile != null) {
|
|
|
|
|
- audioRepository.saveAudioFiles(List.of(audioFile));
|
|
|
|
|
- return new UploadFileRet(audioFileId, null);
|
|
|
|
|
|
|
+ AudioFile audioFile1 = getConvertedAudioFile(audioFileId, file, objectName, ".m4a");
|
|
|
|
|
+ if (audioFile1 != null) {
|
|
|
|
|
+ list.add(audioFile1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("{} 对象转换为 aac 编码失败", objectName);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ audioRepository.saveAudioFiles(list);
|
|
|
|
|
+ return new UploadFileRet(audioFileId, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private AudioFile getConvertedAudioFile(String audioFileId, File file, String originalObjectName, String suffix) {
|
|
private AudioFile getConvertedAudioFile(String audioFileId, File file, String originalObjectName, String suffix) {
|
|
@@ -112,15 +114,23 @@ public class AudioFileProcessor {
|
|
|
throw new Exception("音频转码失败");
|
|
throw new Exception("音频转码失败");
|
|
|
}
|
|
}
|
|
|
String sha256sum = DigestUtil.sha256sum(destPath);
|
|
String sha256sum = DigestUtil.sha256sum(destPath);
|
|
|
|
|
+ MediaProps mediaProps = FFmpegWrapper.getMediaProps(destPath);
|
|
|
|
|
+ if (mediaProps == null || mediaProps.getAudioProps() == null) {
|
|
|
|
|
+ log.error("转码后的 {} 文件 FFmpeg 音频信息为 null", destPath);
|
|
|
|
|
+ throw new Exception("音频编码信息获取失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ AudioProps audioProps = mediaProps.getAudioProps();
|
|
|
|
|
+ String audioCodec = audioProps.getCodecName();
|
|
|
|
|
+ int duration = audioProps.getDuration().intValue();
|
|
|
|
|
+ long bitRate = audioProps.getBitRate();
|
|
|
|
|
|
|
|
ObjectProp objectProp = objectNameService.getObjectProp(originalObjectName, suffix);
|
|
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());
|
|
|
- int duration = 0;
|
|
|
|
|
String codec = "aac";
|
|
String codec = "aac";
|
|
|
- long bitRate = 0;
|
|
|
|
|
return new AudioFile(audioFileId, objectId, duration, codec, bitRate, url);
|
|
return new AudioFile(audioFileId, objectId, duration, codec, bitRate, url);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|