[Libav-user] PTS for H264 encoding
Hema A
hema.angamuthu at gmail.com
Mon Jan 9 10:28:18 CET 2012
Hi,
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;
c->bit_rate = 400000; //c is the AVCodecContext from the mpegTS
stream
c->width = 480;
c->height = 800;
c->time_base= (AVRational){1,12}; //fps - 12
c->max_b_frames=0;
c->pix_fmt = PIX_FMT_YUV420P;
c->profile= FF_PROFILE_H264_BASELINE;
c->level = 10;
c->gop_size = 10;
c->max_qdiff = 4;
c->qmin = 10;
c->qmax=51;
c->qcompress=0.6;
c->keyint_min=10;
c->trellis=0;
c->weighted_p_pred = 2;
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;
int64_t now = av_gettime();
const AVRational codecTimebase = c->time_base;
int64_t rescaledNow = av_rescale_q( now, (AVRational){1, 1000000},
codecTimebase);
CodedFrame->pts = rescaledNow;
...
...
Then called the avcodec_encode_video().
While writing as MpegTS, following is done to set the timestamp of the
packet;
if(streamCodec->coded_frame->pts != AV_NOPTS_VALUE)
{
avpkt.pts = av_rescale_q(streamCodec->coded_frame->pts,
streamCodec->time_base, mpegtsstream->time_base);
}
avpkt - AVPacket for call to av_interleaved_write_frame() in MpegTS format.
streamCodec - Codec associated with the MpegTS stream.
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.
Thanks,
Hema
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120109/978382b0/attachment.html>
More information about the Libav-user
mailing list