[FFmpeg-user] All pts and dts is zero when convert non-formal h264 to Transport Stream

Shu Chaio Yang oceantear at gmail.com
Tue Jun 28 09:00:11 CEST 2011


Hi,

I met some problems, when I try to convert non-formal h264 to Transport
Stream.

First i convert the non-formal h264 to Transport Stream.
-->But , the file can't play by player( such as VLC or Media player)
-->All pts of frames are
zero
-----> i doubt this is the problem

Second, I tried to convert the non-formal h264(called file a) to formal
h264(called file b).
-->The converted h264(file b) can play by VLC.

Finally, i used ffmpeg.exe to convert the converted h264 file(file b) to TS
by below command.
command: ffmpeg -i camera.h26 -vcodec copy -acodec copy -f mpegts camera.ts
-->It can play by VLC.
-->I found the pts of frames is not zero.

Is any one has the experience for any another parameter that i should to
pass to the ffmpeg lib?

Below is part of my codes:
Convert( ){

  int m_nVideoTimeStamp         = 0;
  AVCodecContext *pCodecCtx = m_pVideoStream->codec;
  AVPacket pkt;

                pkt.flags              |= PKT_FLAG_KEY;
                pkt.data                = GetSample();             //one
frame data
                pkt.size                = frame_size;
                pkt.pts                  = m_nVideoTimeStamp++ *
(pCodecCtx->time_base.num * 1000 / pCodecCtx->time_base.den);
                pkt.stream_index = m_pVideoStream->index;

                if (av_write_frame(m_pFormatCtx, &pkt) != 0) {
                    printf("Error while writing audio frame\n");
                    return 0;
                }


AddVideoStream( )
{

    AVCodecContext *pCodecCtx = pStream->codec;
    pCodecCtx->codec_id        = (CodecID)nCodecID;
    pCodecCtx->codec_type    = CODEC_TYPE_VIDEO;

    // Put sample parameters */
    pCodecCtx->bit_rate              = 2000000;
    pCodecCtx->width                 = pProperty->GetWidth();     //CIF:
width:352 height:288
    pCodecCtx->height                = pProperty->GetHeight();
    pCodecCtx->time_base.den  = pProperty->GetFrameRate(); //denominator
    pCodecCtx->time_base.num = 1;
//numerator  //time.base= one frame cost how many times
    pCodecCtx->gop_size           = pProperty->GetFrameRate();
    pCodecCtx->pix_fmt              = PIX_FMT_YUV420P;

}


More information about the ffmpeg-user mailing list