<div>Hi all</div>
<div> </div>
<div>I'm struggling to understand how to set AVPacket::duration field. I have done loads of googling, but never found any working answer. When leaving the field with default 0, which is what it is after avcodec_receive_packet() call, for 30 FPS video I get 34.28 reported (by ffprobe as well as Windows file properties tab). All time-stamps printed by "ffprobe -show_frames" however perfectly correspond with 30 FPS.</div>
<div> </div>
<div>The official documentation says that AVPacket::duration should be set to next_pts - this_pts (<a href="https://ffmpeg.org/doxygen/2.8/structAVPacket.html#af151ba1967c37038088883cd544eeacd">https://ffmpeg.org/doxygen/2.8/structAVPacket.html#af151ba1967c37038088883cd544eeacd</a>), so I take that it means to set the duration of given AVPacket when a next one is received such as</div>
<div> </div>
<div>thisPacket->duration = nextPacket->pts - thisPacket->pts;</div>
<div> </div>
<div>However, when I made a circular AVPacket pool and implemented this, I got 34.28 FPS reported again. Strangely, when the duration is simply hard-coded to 1 it all works:</div>
<div> </div>
<div>void EncodeFrame(AVFormatContext* formatContext, AVCodecContext* encodingContext, AVStream* stream, AVFrame* frame, AVPacket* packet)</div>
<div>{</div>
<div> int ret = avcodec_send_frame(encodingContext, frame);</div>
<div> </div>
<div> while (ret >= 0)</div>
<div> {</div>
<div> ret = avcodec_receive_packet(encodingContext, packet);</div>
<div> </div>
<div> if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)</div>
<div> return;</div>
<div> </div>
<div> if (ret < 0)</div>
<div> return;</div>
<div> </div>
<div> packet->duration = 1;</div>
<div> </div>
<div> av_packet_rescale_ts(packet, encodingContext->time_base, stream->time_base);</div>
<div> </div>
<div> ret = av_write_frame(formatContext, packet);</div>
<div> </div>
<div> av_packet_unref(packet);</div>
<div> }</div>
<div>}</div>
<div> </div>
<div>The encodingContext->time_base is 1/30 and stream->time_base is 1/15360.</div>
<div> </div>
<div>Whilst hard-coding the duration = 1 makes the FPS reported correctly, it just can't be right, because hard-coding a value for all possible scenario would mean that the field is unnecessary and also it would be in conflict with the documentation.</div>
<div> </div>
<div>Please, can anybody advise?</div>
<div> </div>
<div>Thanks a lot!</div>
<div>Lukas</div>