本文主要是介绍【OpenCV】【JavaCV】【Xuggler】【Java】获取视频的编解码器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputStream);grabber.start();System.out.println(JSON.toJSONString(grabber));System.out.println(grabber.getVideoMetadata().get("encoder"));
AVC Coding 即为 H.264
{"aspectRatio":1,"audioBitrate":317375,"audioChannels":2,"audioCodec":86018,"audioFrameRate":46.875,"audioMetadata":{"creation_time":"2021-07-27T03:36:46.000000Z","handler_name":"#Mainconcept MP4 Sound Media Handler","language":"eng"},"audioOptions":{},"audioStream":1,"bitsPerPixel":0,"closeInputStream":true,"deinterlace":false,"delayedTime":0,"format":"mov,mp4,m4a,3gp,3g2,mj2","formatContext":{"null":false},"frameNumber":0,"frameRate":25,"gamma":2.2,"imageHeight":1920,"imageMode":"COLOR","imageScalingFlags":0,"imageWidth":1080,"lengthInAudioFrames":708,"lengthInFrames":378,"lengthInTime":15125333,"lengthInVideoFrames":378,"maxDelay":-1,"metadata":{"creation_time":"2021-07-27T03:36:46.000000Z","major_brand":"mp42","minor_version":"0","compatible_brands":"mp42mp41"},"numBuffers":4,"options":{},"pixelFormat":3,"sampleFormat":1,"sampleMode":"SHORT","sampleRate":48000,"sensorPattern":-1,"timeout":10000,"timestamp":0,"triggerMode":false,"videoBitrate":10681406,"videoCodec":27,"videoFrameRate":25,"videoMetadata":{"creation_time":"2021-07-27T03:36:46.000000Z","handler_name":"\u001FMainconcept Video Media Handler","language":"eng","encoder":"AVC Coding"},"videoOptions":{},"videoStream":0
}
Xuggler
手动安装到本地Maven仓库
mvn install:install-file -Dfile=F:\xuggle-xuggler-5.4.jar -DgroupId=xuggle -DartifactId=xuggle-xuggler -Dversion=5.4 -Dpackaging=jar
<!-- https://mvnrepository.com/artifact/xuggle/xuggle-xuggler --><dependency><groupId>xuggle</groupId><artifactId>xuggle-xuggler</artifactId><version>5.4</version></dependency>
public static void main(String[] args) {long startTime =System.currentTimeMillis();String filename = "F:\\share\\XXX.mp4";// first we create a Xuggler container objectIContainer container = IContainer.make();// we attempt to open up the containerint result = container.open(filename, IContainer.Type.READ, null);// check if the operation was successfulif (result < 0) {throw new RuntimeException("Failed to open media file");}// query how many streams the call to open foundint numStreams = container.getNumStreams();// query for the total durationlong duration = container.getDuration();// query for the file sizelong fileSize = container.getFileSize();// query for the bit ratelong 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 datafor (int i = 0; i < numStreams; i++) {// find the stream objectIStream 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 ***");}}
Number of streams: 2
Duration (ms): 15125333
File Size (bytes): 20776688
Bit Rate: 10989080
*** Start of Stream Info ***
stream 0: type: CODEC_TYPE_VIDEO; codec: CODEC_ID_H264; duration: 377000; start time: 0; timebase: 1/25000; coder tb: 1/50;
width: 1080; height: 1920; format: YUV420P; frame-rate: 25.00;
*** End of Stream Info ***
*** Start of Stream Info ***
stream 1: type: CODEC_TYPE_AUDIO; codec: CODEC_ID_AAC; duration: 726016; start time: 0; timebase: 1/48000; coder tb: 1/48000;
sample rate: 48000; channels: 2; format: FMT_S16
*** End of Stream Info ***
Xuggler-JAR下载地址
https://www.dcm4che.org/maven2/xuggle/xuggle-xuggler/5.4/xuggle-xuggler-5.4.jar
这篇关于【OpenCV】【JavaCV】【Xuggler】【Java】获取视频的编解码器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!