<p>Hi,</p>
<p>For video streaming, we are using FFmpeg libraries and H264 encoding. But there is a delay between the transmitted frames and the display of frames on VLC. We suspect this could be problem with PTS and DTS values of the encoded frame. Comparitively, using MPEG4 codec, we see better performance. Below is code detail;</p>

<p>  c->bit_rate = 400000;           //c is the AVCodecContext from the mpegTS stream<br>  c->width = 480;<br>  c->height = 800;<br>  c->time_base= (AVRational){1,12}; //fps - 12<br>  c->max_b_frames=0;<br>
 c->pix_fmt = PIX_FMT_YUV420P;<br> c->profile= FF_PROFILE_H264_BASELINE;<br> c->level = 10;<br> c->gop_size = 10;<br> c->max_qdiff = 4;<br> c->qmin = 10;<br> c->qmax=51;<br> c->qcompress=0.6;<br> c->keyint_min=10;<br>
 c->trellis=0;<br> c->weighted_p_pred = 2;</p>
<p>When using Mpeg4, we observed that avcodec_encode_video() sets c->coded_frame->pts properly which was incrementing by 7500ms for every subsequent frames. But when using H264, the c->coded_frame->pts was always 0. This value is further affects the pts of the packet being transmitted as MpegTS. We have set the coded frame's PTS as follows;</p>

<p> int64_t now = av_gettime(); <br> const AVRational codecTimebase = c->time_base; <br> int64_t rescaledNow = av_rescale_q( now, (AVRational){1, 1000000}, codecTimebase); <br> CodedFrame->pts = rescaledNow; <br> ... <br>
 ...<br> Then called the avcodec_encode_video().</p>
<p>While writing as MpegTS, following is done to set the timestamp of the packet;</p>
<p>   if(streamCodec->coded_frame->pts != AV_NOPTS_VALUE)<br>   {<br>        avpkt.pts = av_rescale_q(streamCodec->coded_frame->pts, streamCodec->time_base, mpegtsstream->time_base);<br> <br>   }</p>
<p>avpkt - AVPacket for call to av_interleaved_write_frame() in MpegTS format.<br>streamCodec - Codec associated with the MpegTS stream.</p>
<p>Please comment if the PTS and DTS values are set properly. Also is there any change required for specifying the codec context in structure c above while using H264 codec. Please suggest the best configuration for improving the speed of frame display at the receiving end. We are using FFmpeg0.8.5 and latest version of X264.</p>

<p>Thanks,<br>Hema</p>