static hb_buffer_t* x265_encode(hb_work_object_t *w, hb_buffer_t *in) { hb_work_private_t *pv = w->private_data; hb_job_t *job = pv->job; x265_picture pic_in, pic_out; x265_nal *nal; uint32_t nnal; pv->api->picture_init(pv->param, &pic_in); pic_in.stride[0] = in->plane[0].stride; pic_in.stride[1] = in->plane[1].stride; pic_in.stride[2] = in->plane[2].stride; pic_in.planes[0] = in->plane[0].data; pic_in.planes[1] = in->plane[1].data; pic_in.planes[2] = in->plane[2].data; pic_in.poc = pv->frames_in++; pic_in.pts = in->s.start; pic_in.bitDepth = 8; if (in->s.new_chap && job->chapter_markers) { /* * Chapters have to start with an IDR frame so request that this * frame be coded as IDR. Since there may be up to 16 frames * currently buffered in the encoder, remember the timestamp so * when this frame finally pops out of the encoder we'll mark * its buffer as the start of a chapter. */ pic_in.sliceType = X265_TYPE_IDR; hb_chapter_enqueue(pv->chapter_queue, in); } else { pic_in.sliceType = X265_TYPE_AUTO; } if (pv->last_stop != AV_NOPTS_VALUE && pv->last_stop != in->s.start) { hb_log("encx265 input continuity err: last stop %"PRId64" start %"PRId64, pv->last_stop, in->s.start); } pv->last_stop = in->s.stop; save_frame_info(pv, in); if (pv->api->encoder_encode(pv->x265, &nal, &nnal, &pic_in, &pic_out) > 0) { return nal_encode(w, &pic_out, nal, nnal); } return NULL; }
static hb_buffer_t* x265_encode(hb_work_object_t *w, hb_buffer_t *in) { hb_work_private_t *pv = w->private_data; hb_job_t *job = pv->job; x265_picture pic_in, pic_out; x265_nal *nal; uint32_t nnal; pv->api->picture_init(pv->param, &pic_in); pic_in.stride[0] = in->plane[0].stride; pic_in.stride[1] = in->plane[1].stride; pic_in.stride[2] = in->plane[2].stride; pic_in.planes[0] = in->plane[0].data; pic_in.planes[1] = in->plane[1].data; pic_in.planes[2] = in->plane[2].data; pic_in.poc = pv->frames_in++; pic_in.pts = in->s.start; pic_in.bitDepth = 8; if (in->s.new_chap && job->chapter_markers) { if (pv->next_chapter_pts == AV_NOPTS_VALUE) { pv->next_chapter_pts = in->s.start; } /* * Chapter markers are sometimes so close we can get a new one before * the previous marker has been through the encoding queue. * * Dropping markers can cause weird side-effects downstream, including * but not limited to missing chapters in the output, so we need to save * it somehow. */ struct chapter_s *item = malloc(sizeof(struct chapter_s)); if (item != NULL) { item->start = in->s.start; item->index = in->s.new_chap; hb_list_add(pv->delayed_chapters, item); } /* don't let 'work_loop' put a chapter mark on the wrong buffer */ in->s.new_chap = 0; /* * Chapters have to start with an IDR frame so request that this frame be * coded as IDR. Since there may be up to 16 frames currently buffered in * the encoder, remember the timestamp so when this frame finally pops out * of the encoder we'll mark its buffer as the start of a chapter. */ pic_in.sliceType = X265_TYPE_IDR; } else { pic_in.sliceType = X265_TYPE_AUTO; } if (pv->last_stop != in->s.start) { hb_log("encx265 input continuity err: last stop %"PRId64" start %"PRId64, pv->last_stop, in->s.start); } pv->last_stop = in->s.stop; save_frame_info(pv, in); if (pv->api->encoder_encode(pv->x265, &nal, &nnal, &pic_in, &pic_out) > 0) { return nal_encode(w, &pic_out, nal, nnal); } return NULL; }