How To Get Metadata Of Video URL In Spring Boot Application

Posted By : Suraj Verma | 28-Dec-2021

 

 

In this blog, we are going to create a simple spring boot project to extract metadata of the video URL. To extract the metadata of the video URL we are using Java 8 and Spring Boot 2.0 framework. To get the metadata of a video URL, We are using the Ws.Schild library of Java. In this library, we have many classes and services like multimedia object class, Multimedia info class, Through which we are able to get video URL metadata without downloading that video.

 

Step 1: Add Ws.Schild library in .pomx file :

<dependency>

   <groupId>ws.schild</groupId>

   <artifactId>jave-core</artifactId>

   <version>3.2.0</version>

</dependency>

<dependency>

   <groupId>ws.schild</groupId>

   <artifactId>jave-all-deps</artifactId>

   <version>3.2.0</version>

</dependency>

 

Step 2: Write Java code to extract metadata of a video URL :

package com.video;

 

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import ws.schild.jave.EncoderException;

import ws.schild.jave.InputFormatException;

import ws.schild.jave.MultimediaObject;

import ws.schild.jave.info.MultimediaInfo;

import java.net.MalformedURLException;

import java.net.URL;

@SpringBootApplication

public class VideoApplication {

 

   public static void main(String[] args) throws MalformedURLException, EncoderException {

      SpringApplication.run(VideoApplication.class, args);

      MultimediaInfo multimediaInfo = getInfo("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4");

      long minutes = (multimediaInfo.getDuration() / 1000) / 60;

      long seconds = (multimediaInfo.getDuration() / 1000) % 60;

      System.out.println(multimediaInfo.getDuration() + " Milliseconds = " + minutes + " minutes and "+ seconds + " seconds.");

 

   }

 

   public static MultimediaInfo getInfo(String videoUrl) throws MalformedURLException, EncoderException {

      URL url = new URL(videoUrl);

      try {

         MultimediaObject multimediaObject = new MultimediaObject(url);

         MultimediaInfo multimediaInfo = multimediaObject.getInfo();

         return multimediaInfo;

      }catch (InputFormatException e){

         e.printStackTrace();

         return null;

      }

   }

}

 

 

 

Step 3: Run the video application and check the output in the console :

2021-12-25 17:26:25.534  INFO 10693 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8094 (http) with context path ''

2021-12-25 17:26:25.536  INFO 10693 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed

2021-12-25 17:26:25.605  INFO 10693 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)

2021-12-25 17:26:25.737  INFO 10693 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references

2021-12-25 17:26:25.764  INFO 10693 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…

2021-12-25 17:26:32.841  INFO 10693 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!

2021-12-25 17:26:32.860  INFO 10693 --- [           main] com.nowcast.NowcastVideoApplication      : Started VideoApplication in 39.095 seconds (JVM running for 41.309)

653800 Milliseconds = 10 minutes and 53 seconds.

 

Summary :

In this blog, we have learned how to extract metadata from the video URL without downloading that video by using the WS.Schild java library.

 

At Oodles, we excel in building custom enterprise solutions for the diverse industries-specific needs of our clients. Our seasoned developers specialize in using open-source software platforms like Odoo, OFBiz, ERPNext, and Opentaps to build custom ERP applications from the ground up. To learn more about our custom ERP software development services, contact us at [email protected].

 

 

 




 


Please remove URL from text

Comment is required

Sending message..
Connect with us