hb_audio_t * audio;
hb_audio_resample_t * resample;
+ int drop_samples;
#ifdef USE_QSV
// QSV-specific settings
hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
w->private_data = pv;
- pv->job = job;
- pv->audio = w->audio;
- pv->next_pts = (int64_t)AV_NOPTS_VALUE;
+ pv->job = job;
+ pv->audio = w->audio;
+ pv->drop_samples = w->audio->config.in.encoder_delay;
+ pv->next_pts = (int64_t)AV_NOPTS_VALUE;
if (job)
- pv->title = job->title;
+ pv->title = job->title;
else
- pv->title = w->title;
+ pv->title = w->title;
hb_buffer_list_clear(&pv->list);
codec = avcodec_find_decoder(w->codec_param);
if (in->s.flags & HB_BUF_FLAG_EOF)
{
/* EOF on input stream - send it downstream & say that we're done */
- *buf_out = in;
+ decodeAudio(pv, NULL);
+ hb_buffer_list_append(&pv->list, in);
*buf_in = NULL;
+ *buf_out = hb_buffer_list_clear(&pv->list);
return HB_WORK_DONE;
}
int ret;
av_init_packet(&avp);
- avp.data = packet_info->data;
- avp.size = packet_info->size;
- avp.pts = packet_info->pts;
- avp.dts = AV_NOPTS_VALUE;
+ if (packet_info != NULL)
+ {
+ avp.data = packet_info->data;
+ avp.size = packet_info->size;
+ avp.pts = packet_info->pts;
+ avp.dts = AV_NOPTS_VALUE;
+ }
+ else
+ {
+ avp.data = NULL;
+ avp.size = 0;
+ }
ret = avcodec_send_packet(context, &avp);
if (ret < 0 && ret != AVERROR_EOF)
}
pv->duration = (90000. * pv->frame->nb_samples / samplerate);
+ int64_t pts = pv->frame->pts;
+ double duration = pv->duration;
+
if (pv->audio->config.out.codec & HB_ACODEC_PASS_FLAG)
{
// Note that even though we are doing passthru, we had to decode
}
out = hb_audio_resample(pv->resample, pv->frame->extended_data,
pv->frame->nb_samples);
+ if (out != NULL && pv->drop_samples > 0)
+ {
+ /* drop audio samples that are part of the encoder delay */
+ int channels = hb_mixdown_get_discrete_channel_count(
+ pv->audio->config.out.mixdown);
+ int sample_size = channels * sizeof(float);
+ int samples = out->size / sample_size;
+ if (samples <= pv->drop_samples)
+ {
+ hb_buffer_close(&out);
+ pv->drop_samples -= samples;
+ }
+ else
+ {
+ int size = pv->drop_samples * sample_size;
+ double drop_duration = pv->drop_samples * 90000L /
+ pv->audio->config.out.samplerate;
+ memmove(out->data, out->data + size, out->size - size);
+ out->size -= size;
+ pts += drop_duration;
+ duration -= drop_duration;
+ pv->drop_samples = 0;
+ }
+ }
}
if (out != NULL)
{
out->s.scr_sequence = packet_info->scr_sequence;
- out->s.start = pv->frame->pts;
- out->s.duration = pv->duration;
+ out->s.start = pts;
+ out->s.duration = duration;
if (out->s.start == AV_NOPTS_VALUE)
{
out->s.start = pv->next_pts;
AVCodecParameters *codecpar = st->codecpar;
AVDictionaryEntry *tag = av_dict_get(st->metadata, "language", NULL, 0);
- hb_audio_t *audio = calloc(1, sizeof(*audio));
- audio->id = id;
- audio->config.in.track = id;
- audio->config.in.codec = HB_ACODEC_FFMPEG;
- audio->config.in.codec_param = codecpar->codec_id;
+ hb_audio_t *audio = calloc(1, sizeof(*audio));
+ audio->id = id;
+ audio->config.in.track = id;
+ audio->config.in.codec = HB_ACODEC_FFMPEG;
+ audio->config.in.codec_param = codecpar->codec_id;
// set the bitrate to 0; decavcodecaBSInfo will be called and fill the rest
- audio->config.in.bitrate = 0;
+ audio->config.in.bitrate = 0;
+ audio->config.in.encoder_delay = codecpar->initial_padding;
// set the input codec and extradata for Passthru
switch (codecpar->codec_id)