static int x265_close(HEVCEncoderContext *s, uint8_t **pbuf) { int buf_len, ret, i; uint32_t nal_count; x265_nal *p_nal; /* get last compressed pictures */ for(;;) { ret = x265_encoder_encode(s->enc, &p_nal, &nal_count, NULL, NULL); if (ret <= 0) break; for(i = 0; i < nal_count; i++) { add_nal(s, p_nal[i].payload, p_nal[i].sizeBytes); } } if (s->buf_len < s->buf_size) { s->buf = realloc(s->buf, s->buf_len); } *pbuf = s->buf; buf_len = s->buf_len; x265_encoder_close(s->enc); x265_picture_free(s->pic); free(s); return buf_len; }
/* gst_x265_enc_close_encoder * @encoder: Encoder which should close. * * Close x265 encoder. */ static void gst_x265_enc_close_encoder (GstX265Enc * encoder) { if (encoder->x265enc != NULL) { x265_encoder_close (encoder->x265enc); encoder->x265enc = NULL; } }
VideoEncoderX265::~VideoEncoderX265() { if (encoder != NULL){ x265_encoder_close(encoder); encoder = NULL; } //TODO check for x265_cleanup()? //TODO add x265_picture_clean(&x265pic) or x265_picture_free(&x265pic)? }
static void Close(vlc_object_t *p_this) { encoder_t *p_enc = (encoder_t *)p_this; encoder_sys_t *p_sys = p_enc->p_sys; x265_encoder_close(p_sys->h); free(p_sys); }
static void destructor(void *arg) { struct videnc_state *st = arg; if (st->x265) x265_encoder_close(st->x265); if (st->param) x265_param_free(st->param); }
static av_cold int libx265_encode_close(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; av_frame_free(&avctx->coded_frame); x265_param_free(ctx->params); if (ctx->encoder) x265_encoder_close(ctx->encoder); return 0; }
static int open_encoder(struct videnc_state *st, const struct vidsz *size) { if (st->x265) { debug("h265: re-opening encoder\n"); x265_encoder_close(st->x265); } st->param->sourceWidth = size->w; st->param->sourceHeight = size->h; st->x265 = x265_encoder_open(st->param); if (!st->x265) { warning("h265: x265_encoder_open failed\n"); return ENOMEM; } return 0; }
void Video_Encoder_H265::release() { if(_x265_param) { x265_param_free(_x265_param); } if(_x265_picture) { x265_picture_free(_x265_picture); } if(_x265_encoder) { x265_encoder_close(_x265_encoder); } x265_cleanup() ; }
void encx265Close(hb_work_object_t *w) { hb_work_private_t *pv = w->private_data; if (pv->delayed_chapters != NULL) { struct chapter_s *item; while ((item = hb_list_item(pv->delayed_chapters, 0)) != NULL) { hb_list_rem(pv->delayed_chapters, item); free(item); } hb_list_close(&pv->delayed_chapters); } x265_param_free(pv->param); x265_encoder_close(pv->x265); free(pv); w->private_data = NULL; }
int h265_encode_update(struct videnc_state **vesp, const struct vidcodec *vc, struct videnc_param *prm, const char *fmtp) { struct videnc_state *ves; int err = 0; (void)fmtp; if (!vesp || !vc || !prm || prm->pktsize < 3) return EINVAL; ves = *vesp; if (!ves) { ves = mem_zalloc(sizeof(*ves), destructor); if (!ves) return ENOMEM; *vesp = ves; } else { if (ves->x265 && (ves->bitrate != prm->bitrate || ves->pktsize != prm->pktsize || ves->fps != prm->fps)) { x265_encoder_close(ves->x265); ves->x265 = NULL; } } ves->bitrate = prm->bitrate; ves->pktsize = prm->pktsize; ves->fps = prm->fps; err = set_params(ves, prm->fps, prm->bitrate); if (err) return err; return 0; }
bool VideoEncoderX265::reconfigure(VideoFrame* orgFrame, VideoFrame* dstFrame) { int colorspace; if (!needsConfig && orgFrame->getWidth() == xparams->sourceWidth && orgFrame->getHeight() == xparams->sourceHeight && orgFrame->getPixelFormat() == inPixFmt) { return true; } inPixFmt = orgFrame->getPixelFormat(); switch (inPixFmt) { case YUV420P: libavInPixFmt = AV_PIX_FMT_YUV420P; colorspace = X265_CSP_I420; break; /*TODO X265_CSP_I422 not supported yet. Continue checking x265 library releases for its support. case YUV422P: libavInPixFmt = AV_PIX_FMT_YUV422P; colorspace = X265_CSP_I422; break;*/ case YUV444P: libavInPixFmt = AV_PIX_FMT_YUV444P; colorspace = X265_CSP_I444; break; default: utils::debugMsg("Uncompatibe input pixel format"); libavInPixFmt = AV_PIX_FMT_NONE; /*TODO X265_CSP_NONE is not implemented. Continue checking x265 library releases for its support*/ colorspace = -1; return false; break; } picIn->colorSpace = colorspace; x265_param_default_preset(xparams, preset.c_str(), NULL); /*TODO check with NULL profile*/ x265_param_apply_profile(xparams, "main"); x265_param_parse(xparams, "keyint", std::to_string(gop).c_str()); x265_param_parse(xparams, "fps", std::to_string(fps).c_str()); x265_param_parse(xparams, "input-res", (std::to_string(orgFrame->getWidth()) + 'x' + std::to_string(orgFrame->getHeight())).c_str()); //TODO check same management for intra-refresh like x264 //x265_param_parse(xparams, "intra-refresh", std::to_string(0).c_str()); x265_param_parse(xparams, "frame-threads", std::to_string(threads).c_str()); x265_param_parse(xparams, "aud", std::to_string(1).c_str()); x265_param_parse(xparams, "bitrate", std::to_string(bitrate).c_str()); x265_param_parse(xparams, "bframes", std::to_string(0).c_str()); x265_param_parse(xparams, "repeat-headers", std::to_string(0).c_str()); x265_param_parse(xparams, "vbv-maxrate", std::to_string(bitrate*1.05).c_str()); x265_param_parse(xparams, "vbv-bufsize", std::to_string(bitrate*2).c_str()); x265_param_parse(xparams, "rc-lookahead", std::to_string(lookahead).c_str()); x265_param_parse(xparams, "annexb", std::to_string(1).c_str()); x265_param_parse(xparams, "scenecut", std::to_string(0).c_str()); if (annexB) { x265_param_parse(xparams, "repeat-headers", std::to_string(1).c_str()); } if (!encoder) { encoder = x265_encoder_open(xparams); } else { /*TODO reimplement it when a reconfigure method appear*/ x265_encoder_close(encoder); encoder = x265_encoder_open(xparams); } if (!encoder) { utils::errorMsg("Error reconfiguring x265 encoder. At this point encoder should not be NULL..."); return false; } x265_picture_init(xparams, picIn); x265_picture_init(xparams, picOut); needsConfig = false; if (!annexB) { return encodeHeadersFrame(dstFrame); } return true; }