0

我正在尝试使用 mp4parser 写入元数据信息,但在我的代码中,如果是 android 捕获的视频,我将 userDataBox 为空,但如果是其他视频(我已经用下载的视频进行了测试),它不是空的,我成功添加了元数据,我的问题是android捕获的视频有空的userdatabox。有谁能够帮我 ?

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

我的代码在这里:

    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{

}

4

1 回答 1

0

如果 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(...) 方法检查数据是否真的插入到 filestar 和样本之间。然后,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 中的元数据是如何工作的。祝你好运!

于 2014-08-23T11:40:16.790 回答