Verify video encoding is H.264

只愿长相守 提交于 2019-12-11 10:05:21

问题


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

  • Video is H.264 Encoded
  • Audio is AAC Encoded

I've looked into JMF and 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.

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?

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


回答1:


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;



回答2:


This is couple of lines with JCodec ( http://jcodec.org ):

MovieBox movie = MP4Util.parseMovie(new File("path to file"));
Assert.assertEquals(movie.getVideoTrack().getSampleEntries()[0].getFourcc(), "avc1");
for (TrakBox trakBox : movie.getAudioTracks()) {
    Assert.assertEquals(trakBox.getSampleEntries()[0].getFourcc(), "mp4a");
}


来源:https://stackoverflow.com/questions/13734775/verify-video-encoding-is-h-264

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!