<div dir="ltr"><div>I am using a Hi35xx camera processor from HiSilicon.  It is an Arm9 with a video pipeline bolted on the side.  At one end of the pipeline is the CMOS sensor.  At the other end is a H264 encoder.  When I turn on the pipeline, the encoder outputs H264 NAL packets like this:</div><div><br></div><div>    frame0: <SPS>,<PPS>,<SEI>,<key frame></div><div>    frame1: <delta frame></div><div>    frame2: <delta frame></div><div>    ...</div><div>    frameN: <delta frame></div><div>    frameN+1: <SPS>,<PPS>,<SEI><key frame></div><div>    frameN+2: <delta frame></div><div>    frameN+3: <delta frame></div><div>    ...</div><div>    etc.</div><div><br></div><div>I am turning that into HLS clips by doing the following (pseudo code for clarity) :</div><div><br></div><div>    av_register_all();</div><div>    avformat_network_init();</div><div>    </div><div>    avformat_alloc_output_context2(&ctx_out, NULL, "hls", "./foo.m3u8");</div><div>    </div><div>    strm_out = avformat_new_stream(ctx_out, NULL);</div><div>    </div><div>    codec_out = strm_out->codecpar;</div><div>    codec_out->codec_id = AV_CODEC_ID_H264;</div><div>    codec_out->codec_type = AVMEDIA_TYPE_VIDEO;</div><div>    codec_out->width = encoder_width;</div><div>    codec_out->height = encoder_height;</div><div>    codec_out->bit_rate = encoder_bitrate;</div><div>    codec_out->codec_tag = 0;</div><div>    </div><div>    avformat_write_header(ctx_out, NULL);</div><div>    </div><div>    while(get_packet_from_pipeline_encoder(&encoder_packet)) {</div><div>      AVPacket pkt;</div><div>      av_init_packet(&pkt);</div><div>      pkt.stream_index = 0;</div><div><br></div><div>      pkt.dts = AV_NOPTS_VALUE;</div><div>      pkt.pts = AV_NOPTS_VALUE;</div><div>      pkt.duration = (1000000/FRAMERATE);    // frame rate in microseconds</div><div><br></div><div>      pkt.data = encoder_packet.data;</div><div>      pkt.size = encoder_packet.size;</div><div><br></div><div>      if (is_keyframe(&encoder_packet)) {</div><div>        pkt.flags |= AV_PKT_FLAG_KEY;</div><div>      }</div><div><br></div><div>      av_write_frame(ctx_out, &pkt);</div><div>    }</div><div><br></div><div>    av_write_trailer(ctx_out);</div><div>    avformat_free_context(ctx_out);</div><div><br></div><div>This seems to work fine except that the resulting HLS frame rate is not right.  Of course, this happens because I am not setting the pts/dts stuff correctly and ffmpeg lets me know that.  So I have two quetions:</div><div><br></div><div> 1. Am I going about this right?  </div><div> 2. How can I set the pts/dts stuff correctly? </div><div><br></div><div>The encoder is giving me packets and I am submitting them as frames.  Those `<SPS>, <PPS> and <SEI>` packets are really out of band data and don't really have a timestamp.  How can I submit them correctly? </div><div><br></div></div>