Click here to Skip to main content
15,896,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Help me please properly set the timestamps.
I have created an output filter, which takes video (MEDIASUBTAYPE_H264) and audio (MEDIASUBTAYPE_AAC).
I have to put it all into a container FLV. To mix the streams, I use libav.
How to calculate for AVPaket presentation timestamp (pts).

C++
static const REFERENCE_TIME UNITS_PER_SECOND = 10000000i64;
     ....
AVPacket pkt;
av_init_packet( &pkt );
pkt.data = pbData;
pkt.size = lDataLength;
pkt.flags |= AV_PKT_FLAG_KEY;

REFERENCE_TIME startTime = m_lastSampleTime.startTime;

if ( video )
{
    ASSERT( m_codecContextVideo );

    num = m_codecContextVideo->time_base.num;
    den = m_codecContextVideo->time_base.den;

    pkt1.pts          = ??? // ::MulDiv( startTime * den, 1, num * UNITS_PER_SECOND );
    pkt1.stream_index = m_streamVideoOutput->index;
}
else
{
   ASSERT( m_codecContextAudio );

   num = m_codecContextAudio->time_base.num;
   den = m_codecContextAudio->time_base.den;

   pkt1.pts = ??? // ::MulDiv( startTime * den, 1, num * UNITS_PER_SECOND );
   pkt1.stream_index = m_streamAudioOutput->index;
}

ASSERT( m_formatContextOutput );

if ( AllConnected() )
{

    av_interleaved_write_frame( m_formatContextOutput, &pkt1 );
}
else
{
    av_write_frame( m_formatContextOutput, &pkt1 );
}
Posted
Updated 16-Sep-11 2:38am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900