Commit 8d83f8e9 authored by yanzg's avatar yanzg

参数处理

parent 9cdff7e5
package com.yanzuoguang.cloud.file; package com.yanzuoguang.cloud.file;
import com.yanzuoguang.cloud.file.vo.*; 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.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
...@@ -189,33 +191,33 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -189,33 +191,33 @@ public class YzgFileServiceImpl implements YzgFileService {
fileConfig.init(info, fromUrl); fileConfig.init(info, fromUrl);
String serverFullPath = fileConfig.getServerFullPath(fromUrl); String serverFullPath = fileConfig.getServerFullPath(fromUrl);
switch (info.getType()) { try {
case FileHelper.FILE_TYPE_AUDIO: { switch (info.getType()) {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath); case FileHelper.FILE_TYPE_AUDIO: {
info.setBitrate(Double.valueOf(grabber.getVideoBitrate())); MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
break; info.setBitrate(Double.valueOf(parameter.getAudioBitRate()));
} break;
case FileHelper.FILE_TYPE_VIDEO: { }
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath); case FileHelper.FILE_TYPE_VIDEO: {
info.setBitrate(Double.valueOf(grabber.getVideoBitrate())); MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
info.setWidth(Double.valueOf(grabber.getImageWidth())); info.setBitrate(Double.valueOf(parameter.getVideoBitRate()));
info.setHeight(Double.valueOf(grabber.getImageHeight())); info.setWidth(Double.valueOf(parameter.getVideoWidth()));
break; info.setHeight(Double.valueOf(parameter.getVideoHeight()));
} break;
case FileHelper.FILE_TYPE_IMAGE: { }
try { case FileHelper.FILE_TYPE_IMAGE: {
BufferedImage sourceImg = ImageIO.read(new FileInputStream(serverFullPath)); BufferedImage sourceImg = ImageIO.read(new FileInputStream(serverFullPath));
info.setWidth(Double.valueOf(sourceImg.getWidth())); info.setWidth(Double.valueOf(sourceImg.getWidth()));
info.setHeight(Double.valueOf(sourceImg.getHeight())); info.setHeight(Double.valueOf(sourceImg.getHeight()));
} catch (IOException e) { break;
throw new RuntimeException(e); }
case FileHelper.FILE_TYPE_NONE:
default: {
break;
} }
break;
}
case FileHelper.FILE_TYPE_NONE:
default: {
break;
} }
} catch (IOException e) {
throw new RuntimeException(e);
} }
return info; return info;
} }
......
...@@ -206,6 +206,25 @@ public class MediaHelper extends ImageHelper { ...@@ -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