static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                                const AVFrame *pic, int *got_packet)
{
    libx265Context *ctx = avctx->priv_data;
    x265_picture x265pic;
    x265_picture x265pic_out = { { 0 } };
    x265_nal *nal;
    uint8_t *dst;
    int payload = 0;
    int nnal;
    int ret;
    int i;
    if (pic) {
        for (i = 0; i < 3; i++) {
           x265pic.planes[i] = pic->data[i];
           x265pic.stride[i] = pic->linesize[i];
        }
        x265pic.pts = pic->pts;
    }
    ret = x265_encoder_encode(ctx->encoder, &nal, &nnal,
                              pic ? &x265pic : NULL, &x265pic_out);
    if (ret < 0)
        return AVERROR_UNKNOWN;
    if (!nnal)
        return 0;
    for (i = 0; i < nnal; i++)
        payload += nal[i].sizeBytes;
    payload += ctx->header_size;
    ret = ff_alloc_packet(pkt, payload);
    if (ret < 0) {
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
        return ret;
    }
    dst = pkt->data;
    if (ctx->header) {
        memcpy(dst, ctx->header, ctx->header_size);
        dst += ctx->header_size;
        av_freep(&ctx->header);
        ctx->header_size = 0;
    }
    for (i = 0; i < nnal; i++) {
        memcpy(dst, nal[i].payload, nal[i].sizeBytes);
        dst += nal[i].sizeBytes;
        if (is_keyframe(nal[i].type))
            pkt->flags |= AV_PKT_FLAG_KEY;
    }
    pkt->pts = x265pic_out.pts;
    pkt->dts = x265pic_out.dts;
    *got_packet = 1;
    return 0;
}
static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                                const AVFrame *pic, int *got_packet)
{
    libx265Context *ctx = avctx->priv_data;
    x265_picture x265pic;
    x265_picture x265pic_out = { { 0 } };
    x265_nal *nal;
    uint8_t *dst;
    int payload = 0;
    int nnal;
    int ret;
    int i;
    if (pic) {
        for (i = 0; i < 3; i++) {
           x265pic.planes[i] = pic->data[i];
           x265pic.stride[i] = pic->linesize[i];
        }
        x265pic.pts = pic->pts;
    }
    ret = x265_encoder_encode(ctx->encoder, &nal, &nnal,
                              pic ? &x265pic : NULL, &x265pic_out);
    if (ret < 0)
        return AVERROR_UNKNOWN;
    if (!nnal)
        return 0;
    for (i = 0; i < nnal; i++)
        payload += nal[i].sizeBytes;
    payload += ctx->header_size;
    ret = ff_alloc_packet(pkt, payload);
    if (ret < 0) {
        av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
        return ret;
    }
    dst = pkt->data;
    if (ctx->header) {
        memcpy(dst, ctx->header, ctx->header_size);
        dst += ctx->header_size;
        av_freep(&ctx->header);
        ctx->header_size = 0;
    }
    for (i = 0; i < nnal; i++) {
        memcpy(dst, nal[i].payload, nal[i].sizeBytes);
        dst += nal[i].sizeBytes;
        if (is_keyframe(nal[i].type))
            pkt->flags |= AV_PKT_FLAG_KEY;
    }
    pkt->pts = x265pic_out.pts;
    pkt->dts = x265pic_out.dts;
    *got_packet = 1;
    return 0;
}
static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
                                const AVFrame *VAR_2, int *VAR_3)
{
    libx265Context *ctx = VAR_0->priv_data;
    x265_picture x265pic;
    x265_picture x265pic_out = { { 0 } };
    x265_nal *nal;
    uint8_t *dst;
    int VAR_4 = 0;
    int VAR_5;
    int VAR_6;
    int VAR_7;
    if (VAR_2) {
        for (VAR_7 = 0; VAR_7 < 3; VAR_7++) {
           x265pic.planes[VAR_7] = VAR_2->data[VAR_7];
           x265pic.stride[VAR_7] = VAR_2->linesize[VAR_7];
        }
        x265pic.pts = VAR_2->pts;
    }
    VAR_6 = x265_encoder_encode(ctx->encoder, &nal, &VAR_5,
                              VAR_2 ? &x265pic : NULL, &x265pic_out);
    if (VAR_6 < 0)
        return AVERROR_UNKNOWN;
    if (!VAR_5)
        return 0;
    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++)
        VAR_4 += nal[VAR_7].sizeBytes;
    VAR_4 += ctx->header_size;
    VAR_6 = ff_alloc_packet(VAR_1, VAR_4);
    if (VAR_6 < 0) {
        av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet.\n");
        return VAR_6;
    }
    dst = VAR_1->data;
    if (ctx->header) {
        memcpy(dst, ctx->header, ctx->header_size);
        dst += ctx->header_size;
        av_freep(&ctx->header);
        ctx->header_size = 0;
    }
    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) {
        memcpy(dst, nal[VAR_7].VAR_4, nal[VAR_7].sizeBytes);
        dst += nal[VAR_7].sizeBytes;
        if (is_keyframe(nal[VAR_7].type))
            VAR_1->flags |= AV_PKT_FLAG_KEY;
    }
    VAR_1->pts = x265pic_out.pts;
    VAR_1->dts = x265pic_out.dts;
    *VAR_3 = 1;
    return 0;
}
static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ libx265Context *ctx = VAR_0->priv_data; x265_picture x265pic; x265_picture x265pic_out = { { 0 } }; x265_nal *nal; uint8_t *dst; int VAR_4 = 0; int VAR_5; int VAR_6; int VAR_7; if (VAR_2) { for (VAR_7 = 0; VAR_7 < 3; VAR_7++) { x265pic.planes[VAR_7] = VAR_2->data[VAR_7]; x265pic.stride[VAR_7] = VAR_2->linesize[VAR_7]; } x265pic.pts = VAR_2->pts; } VAR_6 = x265_encoder_encode(ctx->encoder, &nal, &VAR_5,
VAR_2 ? &x265pic : NULL, &x265pic_out); if (VAR_6 < 0)
return AVERROR_UNKNOWN; if (!VAR_5)
return 0; for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) VAR_4 += nal[VAR_7].sizeBytes; VAR_4 += ctx->header_size; VAR_6 = ff_alloc_packet(VAR_1, VAR_4); if (VAR_6 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet.\n"); return VAR_6; } dst = VAR_1->data; if (ctx->header) { memcpy(dst, ctx->header, ctx->header_size); dst += ctx->header_size; av_freep(&ctx->header); ctx->header_size = 0; } for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { memcpy(dst, nal[VAR_7].VAR_4, nal[VAR_7].sizeBytes); dst += nal[VAR_7].sizeBytes; if (is_keyframe(nal[VAR_7].type))
VAR_1->flags |= AV_PKT_FLAG_KEY; } VAR_1->pts = x265pic_out.pts; VAR_1->dts = x265pic_out.dts; *VAR_3 = 1; return 0; }