Commit 9cdff7e5 authored by yanzg's avatar yanzg

文件处理

parent 9f467414
...@@ -13,13 +13,13 @@ public class YzgFileVideoImageInfoVo extends YzgFileBaseVo { ...@@ -13,13 +13,13 @@ public class YzgFileVideoImageInfoVo extends YzgFileBaseVo {
* 分辨率x,如: 1920*1080中的1920. * 分辨率x,如: 1920*1080中的1920.
*/ */
@ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1920.") @ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1920.")
private Double x; private Double width;
/** /**
* 分辨率y,如: 1920*1080中的1080. * 分辨率y,如: 1920*1080中的1080.
*/ */
@ApiModelProperty(notes = "分辨率y,如: 1920*1080中的1080.") @ApiModelProperty(notes = "分辨率y,如: 1920*1080中的1080.")
private Double y; private Double height;
/** /**
* 质量 * 质量
...@@ -30,27 +30,27 @@ public class YzgFileVideoImageInfoVo extends YzgFileBaseVo { ...@@ -30,27 +30,27 @@ public class YzgFileVideoImageInfoVo extends YzgFileBaseVo {
public YzgFileVideoImageInfoVo() { public YzgFileVideoImageInfoVo() {
} }
public YzgFileVideoImageInfoVo(String server, String display, long size, String mime, int type, double x, double y, double bitrate) { public YzgFileVideoImageInfoVo(String server, String display, long size, String mime, int type, double width, double height, double bitrate) {
super(server, display, size, mime, type); super(server, display, size, mime, type);
this.x = x; this.width = width;
this.y = y; this.height = height;
this.bitrate = bitrate; this.bitrate = bitrate;
} }
public Double getX() { public Double getWidth() {
return x; return width;
} }
public void setX(Double x) { public void setWidth(Double width) {
this.x = x; this.width = width;
} }
public Double getY() { public Double getHeight() {
return y; return height;
} }
public void setY(Double y) { public void setHeight(Double height) {
this.y = y; this.height = height;
} }
public Double getBitrate() { public Double getBitrate() {
......
...@@ -35,28 +35,28 @@ public class YzgFileVideoImageItemReqVo extends BaseVo { ...@@ -35,28 +35,28 @@ public class YzgFileVideoImageItemReqVo extends BaseVo {
private double quote = 1D; private double quote = 1D;
@ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1920.") @ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1920.")
private double x = 0; private double width = 0;
@ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1080.") @ApiModelProperty(notes = "分辨率x,如: 1920*1080中的1080.")
private double y = 0; private double height = 0;
public YzgFileVideoImageItemReqVo() { public YzgFileVideoImageItemReqVo() {
} }
private YzgFileVideoImageItemReqVo(double size, double quote, double x, double y) { private YzgFileVideoImageItemReqVo(double size, double quote, double width, double height) {
this.size = size; this.size = size;
this.quote = quote; this.quote = quote;
this.x = x; this.width = width;
this.y = y; this.height = height;
} }
public YzgFileVideoImageItemReqVo(String toFile, @NotNull YzgFileVideoImageItemReqVo from) { public YzgFileVideoImageItemReqVo(String toFile, @NotNull YzgFileVideoImageItemReqVo from) {
this(from.size, from.quote, from.x, from.y); this(from.size, from.quote, from.width, from.height);
this.toFile = toFile; this.toFile = toFile;
} }
public YzgFileVideoImageItemReqVo(String toFile, double size, double quote, double x, double y) { public YzgFileVideoImageItemReqVo(String toFile, double size, double quote, double width, double height) {
this(size, quote, x, y); this(size, quote, width, height);
this.toFile = toFile; this.toFile = toFile;
} }
...@@ -84,19 +84,19 @@ public class YzgFileVideoImageItemReqVo extends BaseVo { ...@@ -84,19 +84,19 @@ public class YzgFileVideoImageItemReqVo extends BaseVo {
this.quote = quote; this.quote = quote;
} }
public double getX() { public double getWidth() {
return x; return width;
} }
public void setX(double x) { public void setWidth(double width) {
this.x = x; this.width = width;
} }
public double getY() { public double getHeight() {
return y; return height;
} }
public void setY(double y) { public void setHeight(double height) {
this.y = y; this.height = height;
} }
} }
...@@ -6,11 +6,16 @@ import com.yanzuoguang.util.exception.CodeException; ...@@ -6,11 +6,16 @@ import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.FileHelper; import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
...@@ -180,7 +185,39 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -180,7 +185,39 @@ public class YzgFileServiceImpl implements YzgFileService {
*/ */
@Override @Override
public YzgFileVideoImageInfoVo getInfo(String fromUrl) { public YzgFileVideoImageInfoVo getInfo(String fromUrl) {
return null; YzgFileVideoImageInfoVo info = new YzgFileVideoImageInfoVo();
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 {
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;
}
}
return info;
} }
/** /**
......
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