int encx265Work(hb_work_object_t *w, hb_buffer_t **buf_in, hb_buffer_t **buf_out) { hb_work_private_t *pv = w->private_data; hb_buffer_t *in = *buf_in; if (in->s.flags & HB_BUF_FLAG_EOF) { uint32_t nnal; x265_nal *nal; x265_picture pic_out; hb_buffer_list_t list; hb_buffer_list_clear(&list); // flush delayed frames while (pv->api->encoder_encode(pv->x265, &nal, &nnal, NULL, &pic_out) > 0) { hb_buffer_t *buf = nal_encode(w, &pic_out, nal, nnal); hb_buffer_list_append(&list, buf); } // add the EOF to the end of the chain hb_buffer_list_append(&list, in); *buf_out = hb_buffer_list_clear(&list); *buf_in = NULL; return HB_WORK_DONE; } *buf_out = x265_encode(w, in); return HB_WORK_OK; }
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; }
int encx265Work(hb_work_object_t *w, hb_buffer_t **buf_in, hb_buffer_t **buf_out) { hb_work_private_t *pv = w->private_data; hb_buffer_t *in = *buf_in; if (in->size <= 0) { uint32_t nnal; x265_nal *nal; x265_picture pic_out; hb_buffer_t *last_buf = NULL; // flush delayed frames while (x265_encoder_encode(pv->x265, &nal, &nnal, NULL, &pic_out) > 0) { hb_buffer_t *buf = nal_encode(w, &pic_out, nal, nnal); if (buf != NULL) { if (last_buf == NULL) { *buf_out = buf; } else { last_buf->next = buf; } last_buf = buf; } } // add the EOF to the end of the chain if (last_buf == NULL) { *buf_out = in; } else { last_buf->next = in; } *buf_in = NULL; return HB_WORK_DONE; } *buf_out = x265_encode(w, in); return HB_WORK_OK; }
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; }