JAVA get video file information (without downloading files) by URL link

  Recent projects across a pit: the need to get the length of the video at the time of acquiring the video list on APP, but early when uploading database did not save the data, so some time ago to add a long-field, long time to manually enter the video when you upload, but before the library has thousands of pieces of data do not have this information, if such a one be entered manually, people have to be mad. So who does not mention whether this broken thing, when the video before long the information to its emptiness there. Recently leading me to be a long-category classification of statistical information by video, and leadership reflect the problem, not the ultimate solution to put the process of doing 0. Upon completion of this function, I was thinking what way can the video long before the update to all up. This is certainly not the time to manually enter, you must have java back to the time of admission. But Internet search numerous posts, the final method can be used by only one java implementation that must first be downloaded to the local, and then one by one traversal query. Tens of thousands watching the video on the server, this method to make people think about the scalp tingling.

  Although we did not find a feasible way, but basically get the video information with jave. So go see jave official API, learned through the process FFmpeg multimedia files, and then they see the FFmpeg API, I found that video can get by url when using ffmpeg on the command line. But you have to get MultimediaInfo incoming File jave use toolkit, but they can not create url File. So it will decompile the jar jave hands from the source.

// 源码
public
MultimediaInfo getInfo(File source) throws InputFormatException, EncoderException { FFMPEGExecutor ffmpeg; ffmpeg = locator.createExecutor(); ffmpeg.addArgument("-i"); ffmpeg.addArgument(source.getAbsolutePath()); try { ffmpeg.execute(); } catch(IOException e) { throw new EncoderException(e); } MultimediaInfo multimediainfo; RBufferedReader reader = null; reader = new RBufferedReader(new InputStreamReader(ffmpeg.getErrorStream())); multimediainfo = parseMultimediaInfo(source, reader); ffmpeg.destroy(); return multimediainfo; Exception exception; exception; ffmpeg.destroy(); throw exception; }

Use of an incoming parameter is ffmpeg

source.getAbsolutePath (get absolute file path), so the url created by File is acquired in this project is the path + url.

Then put the incoming path modification became url, but the operation is still there InputFormatException exception. Well, then keep looking all right

Then debug found that although the revised path, but this path is not a closer look

http: //v1.v.123.com \ 11 \ 919 \ 2019 \ zb \ 0181.mp4 
correct url should look like this: http: //v1.v.123.com/11/919/2019/zb /0181.mp4

 Then correct the problem.

 if(path.indexOf("http") != -1) {
            path = source.getPath();
            path = path.split(":")[0] + "://" + path.split(":")[1].substring(1);
            path = path.replace("\\", "/");
        }

 

This finally no problem, you can normally use. Then there are the following call this method, there is a source in acquiring abnormal information they have to modify the path value

multimediainfo = parseMultimediaInfo (source, reader);

 This also and just repeat the above operation on OK. This completely buttoned up.

import lx.jave.AudioAttributes;
import lx.jave.AudioInfo;
import lx.jave.Encoder;
import lx.jave.EncoderException;
import lx.jave.EncodingAttributes;
import lx.jave.InputFormatException;
import lx.jave.MultimediaInfo;
import lx.jave.VideoInfo;
import lx.jave.VideoSize;

/**
 * jave多媒体工具类(需导出jave  jar包) 
 * @author longxiong
 *
 */
public class JaveToolsTest {

    public static void main(String[] args) throwsInputFormatException, EncoderException, Exception { 

        / ** 
         * Get local multimedia information file 
         * / 
        // encoder 
        Encoder Encoder = new new Encoder (); 
        File File = new new File ( "HTTP: //*****018.mp4" ) ;
         // multimedia information 
        MultimediaInfo info = encoder.getInfo (File);
         // long information 
        long DURATION = info.getDuration (); 
        System.out.println ( "video length:" + duration / 1000 + "s" );
         // audio information 
        AudioInfo audio = info.getAudio ();
         int= audio.getBitRate the bitRate ();   // bit rate 
        int channels audio.getChannels = ();   // channel 
        String Decoder audio.getDecoder = ();   // decoder 
        int SRATE = audio.getSamplingRate ();   // Sampling rate 
        System.out.println ( "decoder:" + decoder + ", the channel:" + channels + ", the bit rate:" + bitRate + ", the sampling rate:" + SRATE);
         // video 
        VideoInfo video = info.getVideo ();
         int Bitrate 2 = video.getBitRate (); 
        the Float Frate = video.getFrameRate ();   // the frame rate 
        videoSize videoSize =video.getSize ();
         int height = videoSize.getHeight ();   // Video height 
        int width = videoSize.getWidth ();   // Video width 
        System.out.println ( "Video Frame Rate:" + fRate + ", bit rate: "+ bitRate2 +", video height: "+ height +", width of the video: "+ width); 
        } 
}

 

 

Although it is relatively simple to modify, amend or attach the jar bag.

Link: https: //pan.baidu.com/s/1SpUFZ6DOiJusXZuTG_Qs6A
extraction code: csh0 

 

Guess you like

Origin www.cnblogs.com/qq545505061/p/11224871.html