Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

mpgtx to c# numbers a little off

Back to Forum: Tech Off
  • User profile image
    devnull

    i converted mpgtx to c# but the duration in an mpg file is a little off. maybe my converted methods are incorrect, can anyone see mistakes?

    unsigned short int mpeg::GetSize(off_t offset ) {
        BTRACK;
        return GetByte(offset)*256 + GetByte(offset+1);

    }
    to
    int GetSize(int offset)
    {
        return GetByte(offset) * 256 + GetByte(offset + 1);
    }

    ---

    // 18 following bytes are the bitrate /400
    //read first 16 bytes
    Video->bitrate = GetSize(myoffset);
    // scale
    Video->bitrate <<= 2;
    byte lasttwo = GetByte(myoffset + 2);
    lasttwo >>= 6;
    Video->bitrate |= lasttwo;

    Video->duration = (FileSize*8.0) / (Video->bitrate*400); // 29.92s

    to
    this.VideoInfo.BitRate = GetSize(offset); // eg: 9375
    this.VideoInfo.BitRate <<= 2; // 37500
    byte lastTwo = GetByte(offset + 2); // 35
    lastTwo >>= 6; // 0
    this.VideoInfo.BitRate |= lastTwo; //37500

    this.VideoInfo.Duration = (_fileSize * 8.0) / (this.VideoInfo.BitRate * 400); // 31.17s

    any ideas?

  • User profile image
    W3bbo

    It's probably nothing, but have you checked the BODMAS order of your expression?  How do you know the *256 multiplication isn't being done before the addition with the Offset?

    Try expanding your expression accross multiple lines and see which part is getting the wrong value.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.