fix(file size): use Long instead of float
Float only stores up to 16 million, and file size is stored in bytes. A video can easily be over 16MB (16 million bytes), therefore Long is needed.
This commit is contained in:
@@ -27,5 +27,5 @@ public class ClipOptions {
|
||||
private Integer height;
|
||||
|
||||
@Positive
|
||||
private Float fileSize;
|
||||
private Long fileSize;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Clip {
|
||||
private Float duration;
|
||||
|
||||
@Column(name = "file_size", nullable = false)
|
||||
private Float fileSize;
|
||||
private Long fileSize;
|
||||
|
||||
@Column(name = "video_path", nullable = false, length = 255)
|
||||
private String videoPath;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Vod {
|
||||
private Float duration;
|
||||
|
||||
@Column(name = "file_size", nullable = false)
|
||||
private Float fileSize;
|
||||
private Long fileSize;
|
||||
|
||||
@Column(name = "video_path", nullable = false, length = 255)
|
||||
private String videoPath;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CompressionService {
|
||||
return command;
|
||||
}
|
||||
|
||||
private List<String> buildBitrate(Float length, Float fileSize) {
|
||||
private List<String> buildBitrate(Float length, Long fileSize) {
|
||||
List<String> command = new ArrayList<>();
|
||||
|
||||
float bitrate = ((fileSize * 8) / length) * BITRATE_MULTIPLIER;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.ddf.vodsystem.dto.ClipOptions;
|
||||
import com.ddf.vodsystem.exceptions.FFMPEGException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.api.client.json.Json;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -63,13 +64,12 @@ public class MetadataService {
|
||||
metadata.setStartPoint(0f);
|
||||
|
||||
JsonNode streamNode = extractStreamNode(node);
|
||||
JsonNode formatNode = extractFormatNode(node);
|
||||
|
||||
metadata.setDuration(extractDuration(streamNode));
|
||||
metadata.setDuration(extractDuration(streamNode, formatNode));
|
||||
metadata.setWidth(getWidth(streamNode));
|
||||
metadata.setHeight(getHeight(streamNode));
|
||||
metadata.setFps(extractFps(streamNode));
|
||||
|
||||
JsonNode formatNode = extractFormatNode(node);
|
||||
metadata.setFileSize(extractFileSize(formatNode));
|
||||
extractEndPointFromFormat(metadata, formatNode);
|
||||
|
||||
@@ -84,11 +84,15 @@ public class MetadataService {
|
||||
return streamNode;
|
||||
}
|
||||
|
||||
private Float extractDuration(JsonNode streamNode) {
|
||||
private Float extractDuration(JsonNode streamNode, JsonNode formatNode) {
|
||||
if (streamNode.has(DURATION)) {
|
||||
return Float.valueOf(streamNode.get(DURATION).asText());
|
||||
}
|
||||
|
||||
if (formatNode.has(DURATION)) {
|
||||
return Float.valueOf(formatNode.get(DURATION).asText());
|
||||
}
|
||||
|
||||
throw new FFMPEGException("ffprobe duration missing");
|
||||
}
|
||||
|
||||
@@ -113,9 +117,9 @@ public class MetadataService {
|
||||
return (formatNode != null && !formatNode.isMissingNode()) ? formatNode : null;
|
||||
}
|
||||
|
||||
private Float extractFileSize(JsonNode formatNode) {
|
||||
private Long extractFileSize(JsonNode formatNode) {
|
||||
if (formatNode != null && formatNode.has("size")) {
|
||||
return Float.parseFloat(formatNode.get("size").asText());
|
||||
return Long.parseLong(formatNode.get("size").asText());
|
||||
}
|
||||
|
||||
throw new FFMPEGException("ffprobe file size missing");
|
||||
|
||||
@@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS clips (
|
||||
height INTEGER NOT NULL,
|
||||
fps FLOAT NOT NULL,
|
||||
duration FLOAT NOT NULL,
|
||||
file_size FLOAT NOT NULL,
|
||||
file_size BIGINT NOT NULL,
|
||||
video_path VARCHAR(255) NOT NULL,
|
||||
thumbnail_path VARCHAR(255) NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
@@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS vods (
|
||||
height INTEGER NOT NULL,
|
||||
fps FLOAT NOT NULL,
|
||||
duration FLOAT NOT NULL,
|
||||
file_size FLOAT NOT NULL,
|
||||
file_size BIGINT NOT NULL,
|
||||
video_path VARCHAR(255) NOT NULL,
|
||||
thumbnail_path VARCHAR(255) NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
|
||||
Reference in New Issue
Block a user