xuggle学习-IContainer2
来源:互联网 发布:高顿网校cpa价格知乎 编辑:程序博客网 时间:2024/06/06 17:32
- 通过IContainer主要可以获取视频/音频文件的相关信息以及音视频信息,如起始时间,时常,比特率等等。
public static void main(String[] args) { String filename = "c:/0824.flv"; // Create a Xuggler container object IContainer container = IContainer.make(); // Open up the container if (container.open(filename, IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("could not open file: " + filename); // query how many streams the call to open found int numStreams = container.getNumStreams(); System.out.printf("file \"%s\": %d stream%s; ", filename, numStreams, numStreams == 1 ? "" : "s"); System.out.printf("duration (ms): %s; ", container.getDuration() == Global.NO_PTS ? "unknown" : "" + container.getDuration()/1000); System.out.printf("start time (ms): %s; ", container.getStartTime() == Global.NO_PTS ? "unknown" : "" + container.getStartTime()/1000); System.out.printf("file size (bytes): %d; ", container.getFileSize()); System.out.printf("bit rate: %d; ", container.getBitRate()); System.out.printf("\n"); // and 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(); // and now print out the meta data. 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() == Global.NO_PTS ? "unknown" : "" + stream.getDuration()); System.out.printf("start time: %s; ", container.getStartTime() == Global.NO_PTS ? "unknown" : "" + stream.getStartTime()); System.out.printf("language: %s; ", stream.getLanguage() == null ? "unknown" : stream.getLanguage()); 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()); 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.printf("\n"); } }
getNumStreams():获取流,若输入为音频则只有1,视频则2条流。
getDuration():这个为获取源文件的持续时间,单位默认为微秒getBitRate();文件比特率
对于streamCoder上述方法:
getCodecType();区分文件中流为视频流还是音频流
getCodecID():获取对应流的编码,上述为:CODEC_ID_FLV1,若是音频mp3则为CODEC_ID_MP3;
getTimeBase();获取流的时间单元,