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,27 +191,24 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -189,27 +191,24 @@ public class YzgFileServiceImpl implements YzgFileService {
fileConfig.init(info, fromUrl); fileConfig.init(info, fromUrl);
String serverFullPath = fileConfig.getServerFullPath(fromUrl); String serverFullPath = fileConfig.getServerFullPath(fromUrl);
try {
switch (info.getType()) { switch (info.getType()) {
case FileHelper.FILE_TYPE_AUDIO: { case FileHelper.FILE_TYPE_AUDIO: {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath); MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
info.setBitrate(Double.valueOf(grabber.getVideoBitrate())); info.setBitrate(Double.valueOf(parameter.getAudioBitRate()));
break; break;
} }
case FileHelper.FILE_TYPE_VIDEO: { case FileHelper.FILE_TYPE_VIDEO: {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(serverFullPath); MediaParameter parameter = MediaHelper.getGrabberParameter(serverFullPath);
info.setBitrate(Double.valueOf(grabber.getVideoBitrate())); info.setBitrate(Double.valueOf(parameter.getVideoBitRate()));
info.setWidth(Double.valueOf(grabber.getImageWidth())); info.setWidth(Double.valueOf(parameter.getVideoWidth()));
info.setHeight(Double.valueOf(grabber.getImageHeight())); info.setHeight(Double.valueOf(parameter.getVideoHeight()));
break; break;
} }
case FileHelper.FILE_TYPE_IMAGE: { case FileHelper.FILE_TYPE_IMAGE: {
try {
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) {
throw new RuntimeException(e);
}
break; break;
} }
case FileHelper.FILE_TYPE_NONE: case FileHelper.FILE_TYPE_NONE:
...@@ -217,6 +216,9 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -217,6 +216,9 @@ public class YzgFileServiceImpl implements YzgFileService {
break; 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