Commit 9cdff7e5 authored by yanzg's avatar yanzg

文件处理

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