uint8_t OpenDMLHeader::computePtsDts(void)
{
    // if it is mpeg4-sp, removed packet bitstream & reindex
    if(isMpeg4Compatible(_videostream.fccHandler))  OpenDMLHeader::unpackPacked(  );
    // Now if we have B frames, it is properly tagged
    // Begin by putting PTS=DTS i.e. no B-frames
    for(int i=0;i<_videostream.dwLength;i++)
    {
       odmlIndex *idx=&( _idx[i]);
       idx->pts=ADM_COMPRESSED_NO_PTS;
       idx->dts=frameToUs(i);
    }
    _idx[0].pts=0;
    return 1;
}
/**
    \fn getVideoDuration
*/
uint64_t  OpenDMLHeader::getVideoDuration(void)
{
    if(!_videostream.dwLength) return 0;
    return _idx[_videostream.dwLength-1].dts+frameToUs(1); 
}
/**
        \fn getVideoDuration
        \brief Returns duration of video in us
*/
uint64_t MY_CLASS::getVideoDuration(void)
{
    int lastFrame=ListOfFrames.size();
    if(!lastFrame) return 0;
    lastFrame--;
    int maxLookup=100;
    if(maxLookup>lastFrame) maxLookup=lastFrame;
    int start=lastFrame-maxLookup;

    uint64_t maxPts=0,maxDts=0;
    int      maxPtsIndex=-1,maxDtsIndex=-1;

    // Search for higher PTS in the last N frames
    // and note down its position..
    for(int i=start; i<=lastFrame; i++)
    {
        uint64_t p=ListOfFrames[i]->pts;
        if(p==ADM_NO_PTS)
            continue;
        if(p>maxPts)
        {
            maxPts=p;
            maxPtsIndex=i;
        }
    }
    ADM_info("Found maxPts =%s, %d frames from the end\n",ADM_us2plain(maxPts),lastFrame-maxPtsIndex);
    for(int i=lastFrame; i>=start; i--)
    {
        uint64_t p=ListOfFrames[i]->dts;
        if(p==ADM_NO_PTS)
            continue;
        maxDtsIndex=i;
        maxDts=p;
        break;
    }
    ADM_info("Found maxDts =%s, %d frames from the end\n",ADM_us2plain(maxDts),lastFrame-maxDtsIndex);
    // Case 1: No Pts
    bool usePts=true;
    if(maxPtsIndex==-1)
    {
        usePts=false;
    }
    uint64_t refTime;
    double refDistance;
    if(usePts==true)
    {
        ADM_info("Using PTS..\n");
        refTime=maxPts;
        refDistance=lastFrame-maxPtsIndex;
    } else
    {
        ADM_info("Using DTS..\n");
        refTime=maxDts;
        refDistance=lastFrame-maxDtsIndex;
    }
    double f,g;
    f=1000*1000*1000;
    f/=_videostream.dwRate;
    g=refTime;
    f=f*refDistance;
    g+=f;
    uint64_t duration=(uint64_t)g;
    ADM_info("Using duration of %s\n",ADM_us2plain(duration));
    return duration+frameToUs(1);
}