How to calculate video duration from Dam Video with help xmpDM:value and xmpDM:scale | Community
Skip to main content
Level 2
October 10, 2024
Solved

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

  • October 10, 2024
  • 1 reply
  • 690 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SureshDhulipudi

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);
}

 

1 reply

SureshDhulipudi
Community Advisor
SureshDhulipudiCommunity AdvisorAccepted solution
Community Advisor
October 10, 2024

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);
}