在android中使用mp4parser从android捕获的视频没有用户数据框



我试图使用mp4parser编写元数据信息,但在我的代码中,我在android捕获视频的情况下获得userDataBox空,但在其他视频的情况下(我已经用下载的视频进行了测试)它不是空的,我成功地添加了元数据,我的问题是android捕获的视频具有空userDataBox。有谁能帮我吗?

        moov.getBoxes(UserDataBox.class).size()

My Code is here:

    File mediaStorageDir = new File(
            Environment
                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            "MYFOLDER");
    File f = new File(mediaStorageDir, "VID.mp4");
    if(f.exists())
    {
        Toast.makeText(MainActivity.this," file found",Toast.LENGTH_SHORT).show();
    }
    try {
        fc = new FileInputStream(f).getChannel();
        // fc = new FileInputStream(f).getChannel();
        isoFile = new IsoFile(fc);
        String str = f.getAbsolutePath();
        MovieBox moov = isoFile.getMovieBox();
        // for (Box box : moov.getBoxes()) {
        // System.out.println("box" + box);
        // }

        if(moov.getBoxes(UserDataBox.class).size()>0)
        {
            UserDataBox udta = moov.getBoxes(UserDataBox.class).get(0); 

        }else{

}

如果udta(用户数据框)不存在,您可以创建它。你可能想看看github上的ChangeMetadata示例。

UserDataBox userDataBox;
long sizeBefore;
if ((userDataBox = Path.getPath(tempIsoFile, "/moov/udta")) == null) {
   sizeBefore = 0;
   userDataBox = new UserDataBox();
   tempIsoFile.getMovieBox().addBox(userDataBox);
} else {
   sizeBefore = userDataBox.getSize();
}
MetaBox metaBox;
if ((metaBox = Path.getPath(userDataBox, "meta")) == null) {
   metaBox = new MetaBox();
   userDataBox.addBox(metaBox);
}

XmlBox xmlBox = new XmlBox();
xmlBox.setXml(text);
metaBox.addBox(xmlBox);

现在您已经添加了这些框。不幸的是,该文件包含引用实际视频/音频样本的其他框。这些引用对文件的开头是绝对的,必须进行调整,因为您可能在文件的开头和实际音频/视频样本之间插入了数据。

needsOffsetCorrection(…)方法检查数据是否真的插入到文件星和样本之间。correctChunkOffsets(…)然后对存储在stco (ChunkOffsetBox)中的偏移量进行实际校正。

long sizeAfter = userDataBox.getSize();
if (needsOffsetCorrection(tempIsoFile)) {
    correctChunkOffsets(tempIsoFile, sizeAfter - sizeBefore);
}
videoFileOutputStream = new FileOutputStream(videoFilePath + "_mod.mp4");
tempIsoFile.getBox(videoFileOutputStream.getChannel());

我希望这能帮助你一点了解MP4和MP4元数据是如何工作的。好运!

最新更新