当前位置: 首页 > 工具软件 > Xuggler > 使用案例 >

java使用Xuggler获得视频时长,分辨率,高宽,码率等信息

诸葛令
2023-12-01


https://download.csdn.net/download/iewdyue/9604651


.获取ts流的时长、大小以及分辨率(用到了Xuggle,需要下载对应jar包)
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;

*/
    public static void getVedioInfo(String filename){
 
     
            // 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)
                return ;
            
            // 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();
            long secondDuration = duration/1000000;
            
            System.out.println("时长:"+secondDuration+"秒");
            System.out.println("文件大小:"+fileSize+"M");
         
      
            for (int i=0; i
                IStream stream = container.getStream(i);
                IStreamCoder coder = stream.getStreamCoder();
                if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
                System.out.println("视频宽度:"+coder.getWidth());
                     System.out.println("视频高度:"+coder.getHeight());
                }
            }
    
    }


 类似资料: