diff options
author | John Stebbins <[email protected]> | 2017-02-21 10:33:10 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2017-02-21 10:53:57 -0700 |
commit | 4da397ce15bba63f3554d4bea1bf1c01f43b0a07 (patch) | |
tree | 7b823cfb4945e4c5437584214c92492cbdfd25c9 | |
parent | 9e7986b4735458ffa68f2ed7141eaf105c585618 (diff) |
encavcodecaudio: set encoder time_base to 90khz
Setting the time_base to 90khz reduces rounding errors when converting
back and forth from the default which was sample_rate.
-rw-r--r-- | libhb/encavcodecaudio.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index 227ef289e..b7f2969d9 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -166,6 +166,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job) context->channel_layout = channel_layout; context->channels = pv->out_discrete_channels; context->sample_rate = audio->config.out.samplerate; + context->time_base = (AVRational){1, 90000}; if (audio->config.out.bitrate > 0) { @@ -200,8 +201,8 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job) hb_error("encavcodecaInit: hb_avcodec_open() failed"); return 1; } - w->config->init_delay = av_rescale_q(context->delay, context->time_base, - (AVRational){1, 90000}); + w->config->init_delay = av_rescale(context->initial_padding, + 90000, context->sample_rate); // avcodec_open populates the opts dictionary with the // things it didn't recognize. @@ -364,8 +365,8 @@ static void get_packets( hb_work_object_t * w, hb_buffer_list_t * list ) // The output pts from libav is in context->time_base. Convert it // back to our timebase. - out->s.start = av_rescale_q(pkt.pts, pv->context->time_base, - (AVRational){1, 90000}); + out->s.start = av_rescale_q(pkt.pts, pv->context->time_base, + (AVRational){1, 90000}); out->s.duration = (double)90000 * pv->samples_per_frame / audio->config.out.samplerate; out->s.stop = out->s.start + out->s.duration; @@ -420,11 +421,12 @@ static void Encode(hb_work_object_t *w, hb_buffer_list_t *list) } } - // Libav requires that timebase of audio frames be in sample_rate units - frame.pts = pts + (90000 * pos / (sizeof(float) * + frame.pts = pts + (90000LL * pos / (sizeof(float) * pv->out_discrete_channels * audio->config.out.samplerate)); - frame.pts = av_rescale(frame.pts, pv->context->sample_rate, 90000); + + frame.pts = av_rescale_q(frame.pts, (AVRational){1, 90000}, + pv->context->time_base); // Encode ret = avcodec_send_frame(pv->context, &frame); |