验证视频编码为H.264 [英] Verify video encoding is H.264

查看:154
本文介绍了验证视频编码为H.264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确认视频文件是(使用Java):

I need to verify that a video file is (in Java):

  • 视频已进行H.264编码
  • 音频经过AAC编码

我研究了JMF和Xuggle.

I've looked into JMF and Xuggle.

Xuggle使加载和解码文件以及将其转换为另一种格式变得更加容易,但是我还无法弄清如何确定到目前为止已加载的文件的编码.

Xuggle makes it easier to load and decode the file and turn it into another format, but I've not been able to figure out how to determine the encoding of the file that I've loaded as of yet.

所以我想知道Xuggle是否有能力简单地返回Video&的类型.音频编码文件已经存在,还是我需要读取文件的位来自己确定?

So Im wondering if Xuggle has the capability to simply return the type of Video & Audio encoding a file has or do I need to read the bits of the file to determine this myself?

如果我需要自己决定这一点,有人可以指点我一下有关H.264格式的文献

If I need to determine this myself, can someone point me to some documention on the format of H.264

推荐答案

因此,我查看了Xuggler的Decoding Demo并找到了答案,因此对于以后寻求类似解决方案的任何人,这里都是我编写的代码:

So I looked at Xuggler's Decoding Demo and found my answer, so for anyone in the future looking for a similar solution here is the code I wrote:

    // create a Xuggler container object
    IContainer container = IContainer.make();
    if(container.open(file.getPath(),IContainer.Type.READ,null) < 0) {
        return false;
    }

    // query how many streams the call to open found
    boolean isH264 = false;
    boolean isAAC = false;

    int numStreams = container.getNumStreams();
    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.getCodecID() == ID.CODEC_ID_H264)  {
          isH264 = true;
      }
      if (coder.getCodecID() == ID.CODEC_ID_AAC)  {
          isAAC = true;
      }
    }

    if (container !=null)
    {
      container.close();
      container = null;
    }
    return isH264 && isAAC;

这篇关于验证视频编码为H.264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆