vlc | branch: master | Ilkka Ollakka <il...@videolan.org> | Sun Aug 9 00:37:50 2015 +0300| [5a867c6dd48938ae7a2f3f156656351d0c2e8768] | committer: Ilkka Ollakka
avcodec: scale pts values to libavcodec scale Otherwise bitrate control is quite fobar. Fixes #11538 Pointed out by Sesse > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5a867c6dd48938ae7a2f3f156656351d0c2e8768 --- modules/codec/avcodec/encoder.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c index 730ce94..f977242 100644 --- a/modules/codec/avcodec/encoder.c +++ b/modules/codec/avcodec/encoder.c @@ -1017,7 +1017,7 @@ static void vlc_av_packet_Release(block_t *block) free(b); } -static block_t *vlc_av_packet_Wrap(AVPacket *packet, mtime_t i_length) +static block_t *vlc_av_packet_Wrap(AVPacket *packet, mtime_t i_length, AVCodecContext *context ) { vlc_av_packet_t *b = malloc( sizeof( *b ) ); if( unlikely(b == NULL) ) @@ -1035,6 +1035,8 @@ static block_t *vlc_av_packet_Wrap(AVPacket *packet, mtime_t i_length) p_block->i_dts = packet->dts; if( unlikely( packet->flags & AV_PKT_FLAG_CORRUPT ) ) p_block->i_flags |= BLOCK_FLAG_CORRUPTED; + p_block->i_pts = p_block->i_pts * CLOCK_FREQ * context->time_base.num / context->time_base.den; + p_block->i_dts = p_block->i_dts * CLOCK_FREQ * context->time_base.num / context->time_base.den; return p_block; } @@ -1064,8 +1066,14 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict ) frame->interlaced_frame = !p_pict->b_progressive; frame->top_field_first = !!p_pict->b_top_field_first; - /* Set the pts of the frame being encoded */ - frame->pts = (p_pict->date == VLC_TS_INVALID) ? AV_NOPTS_VALUE : p_pict->date; + /* Set the pts of the frame being encoded + * avcodec likes pts to be in time_base units + * frame number */ + if( likely( p_pict->date > VLC_TS_INVALID ) ) + frame->pts = p_pict->date * p_sys->p_context->time_base.den / + CLOCK_FREQ / p_sys->p_context->time_base.num; + else + frame->pts = AV_NOPTS_VALUE; if ( p_sys->b_hurry_up && frame->pts != AV_NOPTS_VALUE ) { @@ -1140,7 +1148,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict ) } block_t *p_block = vlc_av_packet_Wrap( &av_pkt, - av_pkt.duration / p_sys->p_context->time_base.den ); + av_pkt.duration / p_sys->p_context->time_base.den, p_sys->p_context ); if( unlikely(p_block == NULL) ) { av_free_packet( &av_pkt ); _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits