<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div>Hi,</div><div><br></div><div>Thanks for your reply. But I have one question about video packet pts/dts.</div><div><br></div><div>As we know, video coding support I, P, B picture in general. If video encoder adopts B picture, then output packets' pts will be different from dts. In this case, we can't simply set pts/dts to the number of output packets. How to handle this case?</div><div><br></div><div>Thanks!</div><div><br></div><div>B.R.</div><div><br></div><div>Andrew</div><br><br><br><br><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><br>ÔÚ 2015-09-02 14:34:55£¬"Max Vlasov" <max.vlasov@gmail.com> дµÀ£º<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 2, 2015 at 6:01 AM, qw <span dir="ltr"><<a href="mailto:applemax82@163.com" target="_blank">applemax82@163.com</a>></span> wrote:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:Arial">I'm using avcodec_encode_video2() and avcodec_encode_audio2() to encode video and audio raw data respectively. Can the two encoding function calculate dts/pts/duration of output packets itself? Or I'll calculate those timestamp values by using other method? Does ffmpeg provide examples to calculate those timestamp values?<div><br></div></div></blockquote><div><br><div><div><div>Basically the steps for both streams are (at least I use it for encoding)<br><br></div>-
You initialize the stream codec.time_base with the preferred choice.
The best is frame rate for video (for example Num=1, Den = 25 for Pal
video) and sample_rate for audio (Num = 1 Den 44100 for 44k sound). I
suspect other choices might work, only have in mind that rounding
errors might affect the accuracy of the final stream values <br><br></div>-
Before calling avcodec_encode_* function you set the packet pts value to the
correspondent next one. For choices above you should increase the video
value by one for video and the number of audio samples for audio. <br><br></div>-
Before calling av_interleaved_write_frame you call av_packet_rescale_ts providing the packet with
the changes explained above, the codec time_base explained above and
the stream time_base that is defined by the library (you don't set it
yourself). <br><br></div></div></div></div>
</blockquote></div><br><br><span title="neteasefooter"><p> </p></span>