Commit 8d83f8e9 authored by yanzg's avatar yanzg

参数处理

parent 9cdff7e5
package com.yanzuoguang.cloud.file;
import com.yanzuoguang.cloud.file.vo.*;
import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.MediaParameter;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
......@@ -189,33 +191,33 @@ public class YzgFileServiceImpl implements YzgFileService {
fileConfig.init(info, fromUrl);
String serverFullPath = fileConfig.getServerFullPath(fromUrl);
switch (info.getType()) {
case FileHelper.FILE_TYPE_AUDIO: {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath);
info.setBitrate(Double.valueOf(grabber.getVideoBitrate()));
break;
}
case FileHelper.FILE_TYPE_VIDEO: {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath);
info.setBitrate(Double.valueOf(grabber.getVideoBitrate()));
info.setWidth(Double.valueOf(grabber.getImageWidth()));
info.setHeight(Double.valueOf(grabber.getImageHeight()));
break;
}
case FileHelper.FILE_TYPE_IMAGE: {
try {
try {
switch (info.getType()) {
case FileHelper.FILE_TYPE_AUDIO: {
MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
info.setBitrate(Double.valueOf(parameter.getAudioBitRate()));
break;
}
case FileHelper.FILE_TYPE_VIDEO: {
MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
info.setBitrate(Double.valueOf(parameter.getVideoBitRate()));
info.setWidth(Double.valueOf(parameter.getVideoWidth()));
info.setHeight(Double.valueOf(parameter.getVideoHeight()));
break;
}
case FileHelper.FILE_TYPE_IMAGE: {
BufferedImage sourceImg = ImageIO.read(new FileInputStream(serverFullPath));
info.setWidth(Double.valueOf(sourceImg.getWidth()));
info.setHeight(Double.valueOf(sourceImg.getHeight()));
} catch (IOException e) {
throw new RuntimeException(e);
break;
}
case FileHelper.FILE_TYPE_NONE:
default: {
break;
}
break;
}
case FileHelper.FILE_TYPE_NONE:
default: {
break;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return info;
}
......
......@@ -206,6 +206,25 @@ public class MediaHelper extends ImageHelper {
}
}
/**
* 获取视频缩略图
*
* @param filePath 视频路径
* @throws IOException
*/
public static MediaParameter getGrabberParameter(String filePath) throws IOException {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(filePath);
MediaParameter parameter = new MediaParameter();
try {
// 打开视频
grabber.start();
parameter.init(grabber);
} finally {
grabber.close();
}
return parameter;
}
/**
* 旋转图片
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment