Expand my Community achievements bar.

SOLVED

How to calculate video duration from Dam Video with help xmpDM:value and xmpDM:scale

Avatar

Level 2

I have uploaded video within the dam. i have to calculate video duration for that one ..unable to see duration fields inside props but able to see xmpDM:value and xmpDM:scale with the help of that props how we can calculate exact video duration in hours, minutes and seconds

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

please check , if you can do it in javascript

document.getElementByTagName("video") or get the video object and try .duration

var duration = document.getElementByTagName("video").duration;

and then covert to Time format.

 

 

or you can read the Video Resource Properties like below :

Retrieve the xmpDM:value and xmpDM:scale properties from the video asset's metadata and the calculate the duration

 

public static String calculateVideoDuration(Resource videoResource) {
ValueMap properties = videoResource.getValueMap();
double value = properties.get("xmpDM:value", Double.class);
double scale = properties.get("xmpDM:scale", Double.class);

double durationInSeconds = value / scale;

int hours = (int) (durationInSeconds / 3600);
int minutes = (int) ((durationInSeconds % 3600) / 60);
int seconds = (int) (durationInSeconds % 60);
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

please check , if you can do it in javascript

document.getElementByTagName("video") or get the video object and try .duration

var duration = document.getElementByTagName("video").duration;

and then covert to Time format.

 

 

or you can read the Video Resource Properties like below :

Retrieve the xmpDM:value and xmpDM:scale properties from the video asset's metadata and the calculate the duration

 

public static String calculateVideoDuration(Resource videoResource) {
ValueMap properties = videoResource.getValueMap();
double value = properties.get("xmpDM:value", Double.class);
double scale = properties.get("xmpDM:scale", Double.class);

double durationInSeconds = value / scale;

int hours = (int) (durationInSeconds / 3600);
int minutes = (int) ((durationInSeconds % 3600) / 60);
int seconds = (int) (durationInSeconds % 60);
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}