java - 有没有办法用 Xuggler 获得视频的分辨率?

标签 java video resolution xuggler

我正在开发一个项目,它本质上是一个视频 uploader ,我想知道是否有任何方法可以使用 Java 中的 Xuggler 库获取上传视频的分辨率。

最佳答案

在类里面IStreamCodergetHeightgetWidth 方法。

所以你应该使用这些方法,this sample应该向您展示如何做到这一点。

我为您提取了应该重要的内容。

// Create a Xuggler container object
IContainer container = IContainer.make();

// Open up the container
if (container.open("/path/to/video.avi", 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();

// and iterate through the streams to find the first video stream
int videoStreamId = -1;
IStreamCoder videoCoder = null;
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();

  if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
    videoStreamId = i;
    videoCoder = coder;
    break;
  }
}
if (videoStreamId == -1)
  throw new RuntimeException("could not find video stream in container: "
      +filename);

/*
 * Now we have found the video stream in this file. 
 * Let's open up our decoder so it can do work.
 */
if (videoCoder.open() < 0)
  throw new RuntimeException("could not open video decoder for container: "
      + filename);

// here you have what you need
int height = videoCoder.getHeight();
int width = videoCoder.getWidth();

关于java - 有没有办法用 Xuggler 获得视频的分辨率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12258742/

相关文章:

Java计算出哪个数字先为零

Android VideoView,需要快速切换视频

c# - 如何包装ffmpeg以在c#中转换视频

java - 泛型下界 ('super' ) 问题?

java - 使用prefer-web-inf-classes时weblogic中的ClassCastException

Java:尝试拆分 ", but string.split(""") 不被接受...这该怎么办?

javascript - youtube 视频作为网站背景

java - JavaFX 在不同屏幕上的不同尺寸

java - "Fix"Java 应用程序窗口在辅助监视器分离时隐藏

c# - 如何使用 C# 中的指定容差比较 DateTime 对象?