+static int64_t get_frame_duration( hb_work_private_t * pv, int64_t pts )
+{
+ int i = (pts >> FRAME_INFO_MAX2) & FRAME_INFO_MASK;
+ return pv->frame_info[i].duration;
+}
+
+static hb_buffer_t *nal_encode( hb_work_object_t *w, x264_picture_t *pic_out,
+ int i_nal, x264_nal_t *nal )
+{
+ hb_buffer_t *buf = NULL;
+ hb_work_private_t *pv = w->private_data;
+ hb_job_t *job = pv->job;
+
+ /* Should be way too large */
+ buf = hb_video_buffer_init( job->width, job->height );
+ buf->size = 0;
+ buf->frametype = 0;
+
+ // use the pts to get the original frame's duration.
+ int64_t duration = get_frame_duration( pv, pic_out->i_pts );
+ buf->start = pic_out->i_pts;
+ buf->stop = pic_out->i_pts + duration;
+ buf->renderOffset = pic_out->i_dts;
+ if ( !w->config->h264.init_delay && pic_out->i_dts < 0 )
+ {
+ w->config->h264.init_delay = -pic_out->i_dts;
+ }
+
+ /* Encode all the NALs we were given into buf.
+ NOTE: This code assumes one video frame per NAL (but there can
+ be other stuff like SPS and/or PPS). If there are multiple
+ frames we only get the duration of the first which will
+ eventually screw up the muxer & decoder. */
+ int i;
+ for( i = 0; i < i_nal; i++ )