From: Burkhard P. <pl...@ig...> - 2014-04-07 07:15:14
|
Hi, I thought a bit how to clean up the current mess in the ffmpeg video decoder and I think I came up with a universal solution. The problem is the index tables in quicktime files: They have the advantage that they have implicit compression, which makes them quite small for simple files (e.g. constant framerate, I-frame only). The disadvantage is, that if we use them while demultiplexing, the code becomes like it is now :( The solution is to unpack the indices (stts, ctts, stco, stsc, stss and stps) and make one single index table from them. A separate routine generates the same index from the idx1 or indx chunks of AVI files. The entry for one video frame looks like (qtprivate.h): typedef struct { int64_t position; // Position from the file start int64_t size; // Size int64_t pts; // Presentation time stamp int64_t dts; // Decoding time stamp int64_t duration; // Duration of this packet int flags; // Flags (like in lqt_packet_t) } lqt_packet_index_entry_t; Using qtdump you'll see something like: Packet index (generated) num_entries 35188 pos 374851 pts 0 dts 0 dur 2002 sz 14272 FT I key ref pos 389123 pts 2002 dts 2002 dur 2002 sz 12415 FT P ref pos 401538 pts 4004 dts 4004 dur 2002 sz 18332 FT P ref pos 419870 pts 6006 dts 6006 dur 2002 sz 1336 FT P ref pos 421206 pts 8008 dts 8008 dur 2002 sz 16041 FT P ref pos 437247 pts 10010 dts 10010 dur 2002 sz 20196 FT P ref pos 457443 pts 12012 dts 12012 dur 2002 sz 312 FT P ref .... This reduces "demultiplexing" basically to calls to fseek()/fread() and taking the packet flags from the index. In the current CVS version the packet index is already generated for video streams, but not used yet for demultiplexing. In the meantime you can help a bit by calling qtdump on your files (ideally with really weird GOP patterns) and check if the generated index makes sense. Burkhard |