[Libav-user] question about timestamp calculation in writing MP4 file

(^@^) 1279318717 at qq.com
Mon Oct 6 16:58:39 CEST 2014


Hi, guys
     Anyone takes APIs from avformat lib to write H.264 frames into MP4 file? I am doing this and copied the following code snipset from somewhere.
  
 "
 m_pVideoStream->pts.val = m_nProcessedFramesNum;
 
pkt.pts    = av_rescale_q(m_pVideoStream->pts.val, c->time_base, m_pVideoStream->time_base);
pkt.data   = pData;
pkt.size   = uDataLen;
  
 // Write the compressed frame in the media file
av_interleaved_write_frame(m_pFormatCtx, &pkt)
 "
 But indeed, I do not understand why I have to convert the video frame's sequence number, m_nProcessedFramesNum, to AVPacket's PTS with the formula,
  
 av_rescale_q(m_pVideoStream->pts.val, c->time_base, m_pVideoStream->time_base);
  
 in above, c is AVCodecContext of the video stream (m_pVideoStream). And the most wired thing to me is that c->time_base and m_pVideoStream->time_base have
 different values, say, c->time_base is {1,30 }, but m_pVideoStream->time_base takes {1, 15360 }. So much the gap is!
  
 If I directly set pts to m_nProcessedFramesNum, the outcome MP4 file would be decoded and presented extremely faster than expected. What hell is the reason?
 Could anyone please help me to explain this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141006/4029cc0d/attachment.html>


More information about the Libav-user mailing list