您好,欢迎来到暴趣科技网。
搜索
您的当前位置:首页Java多媒体播放器(二)

Java多媒体播放器(二)

来源:暴趣科技网

No.2 Xuggler


一、简介

        Xuggler is the easy way to uncompress, modify, and re-compress any media file (or stream) from Java.

二、示例

import com.xuggle.xuggler.ICodec;   //该程序来自互联网,官网的tutorials已经打不开了
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;

public class VideoInfo {
    
    private static final String filename = "c:/myvideo.mp4";
    
    public static void main(String[] args) {
        
        // first we create a Xuggler container object
        IContainer container = IContainer.make();
        
        // we attempt to open up the container
        int result = container.open(filename, IContainer.Type.READ, null);
        
        // check if the operation was successful
        if (result<0)
            throw new RuntimeException("Failed to open media file");
        
        // query how many streams the call to open found
        int numStreams = container.getNumStreams();
        
        // query for the total duration
        long duration = container.getDuration();
        
        // query for the file size
        long fileSize = container.getFileSize();

        // query for the bit rate
        long bitRate = container.getBitRate();
        
        System.out.println("Number of streams: " + numStreams);
        System.out.println("Duration (ms): " + duration);
        System.out.println("File Size (bytes): " + fileSize);
        System.out.println("Bit Rate: " + bitRate);
        
        // iterate through the streams to print their meta data
        for (int i=0; i<numStreams; i++) {
            
            // find the stream object
            IStream stream = container.getStream(i);
            
            // get the pre-configured decoder that can decode this stream;
            IStreamCoder coder = stream.getStreamCoder();
            
            System.out.println("*** Start of Stream Info ***");
            
            System.out.printf("stream %d: ", i);
            System.out.printf("type: %s; ", coder.getCodecType());
            System.out.printf("codec: %s; ", coder.getCodecID());
            System.out.printf("duration: %s; ", stream.getDuration());
            System.out.printf("start time: %s; ", container.getStartTime());
            System.out.printf("timebase: %d/%d; ",
                 stream.getTimeBase().getNumerator(),
                 stream.getTimeBase().getDenominator());
            System.out.printf("coder tb: %d/%d; ",
                 coder.getTimeBase().getNumerator(),
                 coder.getTimeBase().getDenominator());
            System.out.println();
            
            if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
                System.out.printf("sample rate: %d; ", coder.getSampleRate());
                System.out.printf("channels: %d; ", coder.getChannels());
                System.out.printf("format: %s", coder.getSampleFormat());
            } 
            else if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
                System.out.printf("width: %d; ", coder.getWidth());
                System.out.printf("height: %d; ", coder.getHeight());
                System.out.printf("format: %s; ", coder.getPixelType());
                System.out.printf("frame-rate: %5.2f; ", coder.getFrameRate().getDouble());
            }
            
            System.out.println();
            System.out.println("*** End of Stream Info ***");
            
        }
        
    }

}

三、评价

        非常好的开源项目,定制性和可扩展性也很强,同时自身体积小巧。不过遗憾的是,由于作者自身原因已停止更新(最新版为5.2),又没人接手。总之,虽然停止更新会存在一些问题,但目前来看(短期内)还是非常不错的选择,同时也期待今后能有大神接手这个项目或开发出更强大的替代品!

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baoquwan.com 版权所有 湘ICP备2024080961号-7

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务