zpon / mp4v2

Automatically exported from code.google.com/p/mp4v2
Other
0 stars 0 forks source link

last entry of stsc property "firstSample" is wrong after MP4Track::FinishWrite() #121

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
stsc firstSample property is updated by the function 
MP4Track::UpdateSampleToChunk(), which is called from 
MP4Track::WriteChunkBuffer().

WriteChunkBuffer() is usually called in the middle of MP4Track::WriteSample(), 
where MP4Track::m_writeSampleId holds "current sample id", and finally 
incremented at the last of WriteSample().

However, WriteChunkBufffer() is also called from FinishWrite(), where 
m_writeSampleId doesn't point to "current sample id" anymore. At that point, 
m_writeSampleId holds the last sample id + 1.
Therefore, stsc firstSample property will be off, at this point.

firstSample property seems to be intended only for optimization, and not 
actually written to file, therefore it does no harm if you just discard 
MP4File/MP4Track instance after FinishWrite().
However, as I want to keep and use MP4File/MP4Track instance after 
FinishWrite() for optimization purpose, it's no good.

Currently, official Optimize() requires re-opening and re-parsing the result, 
and it's not optimal. MP4File already keeps MP4 box structure on memory!
Therefore, I want to keep MP4File instance after FinishWrite(), and just copy 
to new file (in optimal order) using the existing instance.

Original issue reported on code.google.com by honeycom...@gmail.com on 18 Sep 2011 at 2:45

GoogleCodeExporter commented 8 years ago
As far as I understand, just decrement m_writeSampleId seems to fix this, at 
the top of FinishWrite().

Original comment by honeycom...@gmail.com on 18 Sep 2011 at 3:14