[Libav-user] AVPacket duration

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] AVPacket duration

LUKY CMUKY
Hi all
 
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.
 
The official documentation says that AVPacket::duration should be set to next_pts - this_pts (https://ffmpeg.org/doxygen/2.8/structAVPacket.html#af151ba1967c37038088883cd544eeacd), so I take that it means to set the duration of given AVPacket when a next one is received such as
 
thisPacket->duration = nextPacket->pts - thisPacket->pts;
 
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:
 
void EncodeFrame(AVFormatContext* formatContext, AVCodecContext* encodingContext, AVStream* stream, AVFrame* frame, AVPacket* packet)
{
  int ret = avcodec_send_frame(encodingContext, frame);
 
  while (ret >= 0)
  {
    ret = avcodec_receive_packet(encodingContext, packet);
 
    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
      return;
 
    if (ret < 0)
      return;
 
    packet->duration = 1;
 
    av_packet_rescale_ts(packet, encodingContext->time_base, stream->time_base);
 
    ret = av_write_frame(formatContext, packet);
 
    av_packet_unref(packet);
  }
}
 
The encodingContext->time_base is 1/30 and stream->time_base is 1/15360.
 
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.
 
Please, can anybody advise?
 
Thanks a lot!
Lukas

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".