Menu

#5 udta/mdta extraction/insertion

v1.0_(example)
open
nobody
MDAT (1)
5
2015-10-08
2015-10-08
A. Buisson
No

Hi, I use Bento4 to extract atoms from mp4 and inject those atoms into new mp4 file and I found the following issue.
When I try to extract udta/mdat atom with sub atom in the mdat atom (ie. hdlr, ilist, etc... see attached png file) Bento4 stop the parsing at the mdat level (why not ...) and claim as expected that the atom ise is for example 144 bytes. But when I do the "moov->AddChild(udta->Clone());" in the output file there is an issue because the MP4 output file, the mdta atom has only a size of 12 bytes.

Any help will be welcome !

here is the pseudo-code I used to extract the atom (note that in the real code all return are checked with AP4_FAILED and no error is found .... )

AP4_Atom extract(...) {
AP4_ByteStream
input = NULL;
AP4_Result result = AP4_FileByteStream::Create(input_name.c_str(), AP4_FileByteStream::STREAM_MODE_READ, input);
if (AP4_FAILED(result)) {
return NULL;
}

// parse the atoms
AP4_AtomParent top_level;
AP4_Atom atom;
AP4_AtomFactory& atom_factory = AP4_DefaultAtomFactory::Instance;
while (atom_factory.CreateAtomFromStream(
input, atom) == AP4_SUCCESS) {
top_level.AddChild(atom);
}

atom = top_level.FindChild("moov/udta");
if (atom == NULL)
{
return NULL;
}

result = atom->Detach();
input->Release();
return atom;
}

and the pseudo-code use to insert

void insert(AP4_Atom atom)
{
AP4_Movie
movie = new AP4_Movie(civox->media_timescale);
AP4_File file(movie);
....
AP4_MoovAtom moov = movie->GetMoovAtom();
result = moov->AddChild(atom->Clone());
....
AP4_ByteStream
output;
result = AP4_FileByteStream::Create (mp4File, AP4_FileByteStream::STREAM_MODE_WRITE, output);
result = AP4_FileWriter::Write(file, *output);
output->Release();
....
}

1 Attachments

Discussion


Log in to post a comment.