Commit 5a867c6d authored by Ilkka Ollakka's avatar Ilkka Ollakka

avcodec: scale pts values to libavcodec scale

Otherwise bitrate control is quite fobar.

Fixes #11538

Pointed out by Sesse
parent ddbe9dc3
......@@ -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 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment