Get Video size Java

Source: Internet
Author: User

First, get the video address from the text, download the video to the local, get the video size information

This way is very slow, very troublesome because the first to download this video to the local, in the local access to this video information in the removal of this video (do not delete it can also, mainly time long thing more than a station space)

But did not find a good method can only do so, if there is a good way to ask you to enlighten me very much thank you ...


Second, code:

Package com.soufun.util;
Import It.sauronsoftware.jave.Encoder;

Import It.sauronsoftware.jave.MultimediaInfo;
Import Java.io.DataInputStream;
Import Java.io.DataOutputStream;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import java.net.HttpURLConnection;
Import java.net.MalformedURLException;
Import java.net.URISyntaxException;
Import Java.net.URL;

Import Java.util.Date; /** * Get the size of the screen * * @author User * * */public class Videosize {public static void main (string[] args) throws Urisynta
		Xexception, malformedurlexception {Date begin = new Date (); try {getremotefile ("Http://video2s.soufun.com/2015/04/27/bj/mp4/ef9ba790c9e74742ae5898aefe9232a1.mp4", "d:/
		Test1.flv ");
		catch (IOException E1) {//TODO auto-generated catch block E1.printstacktrace ();
		///download to local video file Source = new file ("d:/test1.flv");
		Encoder encoder = new encoder ();
			try {//Get multimedia information object Multimediainfo m = encoder.getinfo (source);The call method gets the long ls = m.getduration (); System.out.println ("The length of this video is:" + ls/1000 +) seconds.
		");
		catch (Exception e) {e.printstacktrace ();
		Date end = new Date ();
		Long time = End.gettime ()-begin.gettime ();
	System.out.println ("time-consuming" + time/1000); private static Boolean Getremotefile (String strurl, String fileName) throws IOException {URL url = new URL (strur
		L);
		HttpURLConnection conn = (httpurlconnection) url.openconnection ();
		DataInputStream input = new DataInputStream (Conn.getinputstream ());
		DataOutputStream output = new DataOutputStream (new FileOutputStream (FileName));
		byte[] buffer = new byte[1024 * 8];
		int count = 0;
		while ((count = input.read (buffer)) > 0) {output.write (buffer, 0, count);
		} output.close ();
		Input.close ();
	return true;
 }
}


Note: The download address of the Jave package used in the program is as follows:

Click to download jave1.0.1 rack package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.