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:
2026-07-07 20:48:37 +02:00
parent a66b9898e8
commit e1e6fe0046
8 changed files with 35 additions and 38 deletions

View File

@@ -27,5 +27,5 @@ public class ClipOptions {
private Integer height;
@Positive
private Float fileSize;
private Long fileSize;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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");