jetson-ffmpeg icon indicating copy to clipboard operation
jetson-ffmpeg copied to clipboard

Encode h264 packet but dts and pts are all 0

Open yueyihua opened this issue 2 years ago • 0 comments

When encode YUV420P to h264 packet stream using h264_nvmpi codec,but the dts and pts are all zero. This is My code: /* send the frame to the encoder */ ret = avcodec_send_frame(enc_ctx, frame); if (ret < 0) { GLOG(G_ERROR) << "Error sending a frame for encoding"; return ret; }

while (ret >= 0)
{
    ret = avcodec_receive_packet(enc_ctx, pkt);
    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
    {
        ret = 0;
        break;
    }
    else if (ret < 0)
    {
        GLOG(G_ERROR) << "Error during encoding";
        return ret;
    }

    GLOG(G_INFO) << "pkt->pts: " << pkt->pts << ", pkt->dts: " << pkt->dts << ", pkt->duration: " << pkt->duration;
    av_packet_rescale_ts(pkt, enc_ctx->time_base, st->time_base);

    /* Write the compressed frame to the media file. */
    ret = av_interleaved_write_frame(fmtctx, pkt);
    if (ret < 0)
    {
        GLOG(G_WARNING) << "Warning during send frame";
    }
    av_packet_unref(pkt);
}

My LOG: [INFO] Sat Oct 9 17:17:13 2021 | (src/ffmpeg_rtp.cpp:214) | pkt->pts: 0, pkt->dts: 0, pkt->duration: 0

yueyihua avatar Oct 09 '21 09:10 yueyihua