[vlc-commits] avcodec: scale pts values to libavcodec scale

Ilkka Ollakka git at videolan.org
Sat Oct 10 18:06:24 CEST 2015


vlc/vlc-2.2 | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Aug  9 00:37:50 2015 +0300| [e796bcef22647c958a87812fa1c3881dbb69f728] | committer: Ilkka Ollakka

avcodec: scale pts values to libavcodec scale

Otherwise bitrate control is quite fobar.

Fixes #11538

Pointed out by Sesse

(cherry picked from commit 5a867c6dd48938ae7a2f3f156656351d0c2e8768)
Signed-off-by: Ilkka Ollakka <ileoo at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=e796bcef22647c958a87812fa1c3881dbb69f728
---

 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 0b25b6c..ab95191 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -1029,7 +1029,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) )
@@ -1047,6 +1047,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;
 }
@@ -1077,8 +1079,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 ? p_pict->date : AV_NOPTS_VALUE;
+        /* 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 )
         {
@@ -1154,7 +1162,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 );



More information about the vlc-commits mailing list